cr: Make sure gn isn't enabled automatically
[chromium-blink-merge.git] / ios / web / ui_web_view_util_unittest.mm
blob0354579d5c62b8c8f4f2611ccec4110768708d2f
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.
5 #import "ios/web/ui_web_view_util.h"
7 #import "ios/web/public/test/test_web_client.h"
8 #include "testing/gtest_mac.h"
9 #include "testing/platform_test.h"
11 namespace {
13 // Returns user agent string registered for UIWebView.
14 NSString* GetUserAgent() {
15   return [[NSUserDefaults standardUserDefaults] stringForKey:@"UserAgent"];
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_;
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());
41 // Tests registration of a desktop user agent.
42 TEST_F(UIWebViewUtilTest, BuildAndRegisterDesktopUserAgentForUIWebView) {
43   web::BuildAndRegisterUserAgentForUIWebView(@"1231546541321", YES);
44   EXPECT_NSEQ(@"DesktopUA (1231546541321)", GetUserAgent());
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());
54 }  // namespace