aw_media_url_interceptor_unittest.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/browser/aw_media_url_interceptor.h"
  5. #include <memory>
  6. #include <string>
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. using testing::Test;
  9. namespace android_webview {
  10. namespace {
  11. // Sentinel value to check whether the fields have been set.
  12. const int UNSET_VALUE = -1;
  13. class AwMediaUrlInterceptorTest : public Test {
  14. public:
  15. AwMediaUrlInterceptorTest()
  16. : fd_(UNSET_VALUE),
  17. offset_(UNSET_VALUE),
  18. size_(UNSET_VALUE),
  19. url_interceptor_(new AwMediaUrlInterceptor()) {}
  20. protected:
  21. int fd_;
  22. int64_t offset_;
  23. int64_t size_;
  24. std::unique_ptr<AwMediaUrlInterceptor> url_interceptor_;
  25. };
  26. } // namespace
  27. TEST_F(AwMediaUrlInterceptorTest, TestInterceptValidAssetUrl) {
  28. // This asset file exists in the android_webview_unittests-debug.apk.
  29. // See gyp rule android_webview_unittests_apk.
  30. const std::string valid_asset_url("file:///android_asset/asset_file.ogg");
  31. ASSERT_TRUE(
  32. url_interceptor_->Intercept(valid_asset_url, &fd_, &offset_, &size_));
  33. EXPECT_NE(UNSET_VALUE, fd_);
  34. EXPECT_NE(UNSET_VALUE, offset_);
  35. EXPECT_NE(UNSET_VALUE, size_);
  36. }
  37. // TODO(crbug/784572)
  38. TEST_F(AwMediaUrlInterceptorTest, DISABLED_TestInterceptInvalidAssetUrl) {
  39. // This asset file does not exist in the android_webview_unittests-debug.apk.
  40. // See gyp rule android_webview_unittests_apk.
  41. const std::string invalid_asset_url(
  42. "file:///android_asset/file_does_not_exist.ogg");
  43. ASSERT_FALSE(
  44. url_interceptor_->Intercept(invalid_asset_url, &fd_, &offset_, &size_));
  45. EXPECT_EQ(UNSET_VALUE, fd_);
  46. EXPECT_EQ(UNSET_VALUE, offset_);
  47. EXPECT_EQ(UNSET_VALUE, size_);
  48. }
  49. TEST_F(AwMediaUrlInterceptorTest, TestInterceptNonAssetUrl) {
  50. // This url does not refer to an asset in the apk.
  51. const std::string non_asset_url("file:///sdcard/file.txt");
  52. ASSERT_FALSE(
  53. url_interceptor_->Intercept(non_asset_url, &fd_, &offset_, &size_));
  54. EXPECT_EQ(UNSET_VALUE, fd_);
  55. EXPECT_EQ(UNSET_VALUE, offset_);
  56. EXPECT_EQ(UNSET_VALUE, size_);
  57. }
  58. } // namespace android_webview