OLD | NEW |
(Empty) | |
| 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 |
| 5 #import "ios/web/ui_web_view_util.h" |
| 6 |
| 7 #import "ios/web/public/test/test_web_client.h" |
| 8 #include "testing/gtest_mac.h" |
| 9 #include "testing/platform_test.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 // Returns user agent string registered for UIWebView. |
| 14 NSString* GetUserAgent() { |
| 15 return [[NSUserDefaults standardUserDefaults] stringForKey:@"UserAgent"]; |
| 16 } |
| 17 |
| 18 class UIWebViewUtilTest : public PlatformTest { |
| 19 protected: |
| 20 void SetUp() override { |
| 21 PlatformTest::SetUp(); |
| 22 test_web_client_.SetUserAgent("DesktopUA", true); |
| 23 test_web_client_.SetUserAgent("RegularUA", false); |
| 24 web::SetWebClient(&test_web_client_); |
| 25 } |
| 26 void TearDown() override { |
| 27 web::SetWebClient(nullptr); |
| 28 PlatformTest::TearDown(); |
| 29 } |
| 30 private: |
| 31 // WebClient that returns test user agent. |
| 32 web::TestWebClient test_web_client_; |
| 33 }; |
| 34 |
| 35 // Tests registration of a non-desktop user agent. |
| 36 TEST_F(UIWebViewUtilTest, BuildAndRegisterNonDesktopUserAgentForUIWebView) { |
| 37 web::BuildAndRegisterUserAgentForUIWebView(@"1231546541321", NO); |
| 38 EXPECT_NSEQ(@"RegularUA (1231546541321)", GetUserAgent()); |
| 39 } |
| 40 |
| 41 // Tests registration of a desktop user agent. |
| 42 TEST_F(UIWebViewUtilTest, BuildAndRegisterDesktopUserAgentForUIWebView) { |
| 43 web::BuildAndRegisterUserAgentForUIWebView(@"1231546541321", YES); |
| 44 EXPECT_NSEQ(@"DesktopUA (1231546541321)", GetUserAgent()); |
| 45 } |
| 46 |
| 47 // Tests web::RegisterUserAgentForUIWebView function that it correctly registers |
| 48 // arbitrary user agent. |
| 49 TEST_F(UIWebViewUtilTest, RegisterUserAgentForUIWebView) { |
| 50 web::RegisterUserAgentForUIWebView(@"UA"); |
| 51 EXPECT_NSEQ(@"UA", GetUserAgent()); |
| 52 } |
| 53 |
| 54 } // namespace |
OLD | NEW |