Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: ios/chrome/browser/web/chrome_web_client_unittest.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/web/chrome_web_client.mm ('k') | ios/chrome/browser/web/chrome_web_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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 #include "ios/chrome/browser/web/chrome_web_client.h"
6
7 #include <UIKit/UIKit.h>
8
9 #include <memory>
10
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/memory/ptr_util.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/sys_string_conversions.h"
15 #import "ios/web/public/test/js_test_util.h"
16 #include "ios/web/public/test/scoped_testing_web_client.h"
17 #include "ios/web/public/test/test_browser_state.h"
18 #include "ios/web/public/test/web_test.h"
19 #import "ios/web/public/web_view_creation_util.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/gtest_mac.h"
22
23 namespace {
24
25 // Test fixture for testing ChromeWebClient.
26 typedef web::WebTest ChromeWebClientTest;
27
28 TEST_F(ChromeWebClientTest, UserAgent) {
29 std::vector<std::string> pieces;
30
31 // Check if the pieces of the user agent string come in the correct order.
32 ChromeWebClient web_client;
33 std::string buffer = web_client.GetUserAgent(false);
34
35 pieces = base::SplitStringUsingSubstr(
36 buffer, "Mozilla/5.0 (", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
37 ASSERT_EQ(2u, pieces.size());
38 buffer = pieces[1];
39 EXPECT_EQ("", pieces[0]);
40
41 pieces = base::SplitStringUsingSubstr(
42 buffer, ") AppleWebKit/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
43 ASSERT_EQ(2u, pieces.size());
44 buffer = pieces[1];
45 std::string os_str = pieces[0];
46
47 pieces =
48 base::SplitStringUsingSubstr(buffer, " (KHTML, like Gecko) ",
49 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
50 ASSERT_EQ(2u, pieces.size());
51 buffer = pieces[1];
52 std::string webkit_version_str = pieces[0];
53
54 pieces = base::SplitStringUsingSubstr(
55 buffer, " Safari/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
56 ASSERT_EQ(2u, pieces.size());
57 std::string product_str = pieces[0];
58 std::string safari_version_str = pieces[1];
59
60 // Not sure what can be done to better check the OS string, since it's highly
61 // platform-dependent.
62 EXPECT_FALSE(os_str.empty());
63
64 EXPECT_FALSE(webkit_version_str.empty());
65 EXPECT_FALSE(safari_version_str.empty());
66
67 EXPECT_EQ(0u, product_str.find("CriOS/"));
68 }
69
70 // Tests that ChromeWebClient provides print script and does not provide
71 // windowOpenFix script for WKWebView.
72 TEST_F(ChromeWebClientTest, WKWebViewEarlyPageScript) {
73 // Chrome scripts rely on __gCrWeb object presence.
74 web::TestBrowserState browser_state;
75 WKWebView* web_view = web::BuildWKWebView(CGRectZero, &browser_state);
76 web::ExecuteJavaScript(web_view, @"__gCrWeb = {};");
77
78 web::ScopedTestingWebClient web_client(base::MakeUnique<ChromeWebClient>());
79 NSString* script = web_client.Get()->GetEarlyPageScript();
80 web::ExecuteJavaScript(web_view, script);
81 EXPECT_NSEQ(@"object",
82 web::ExecuteJavaScript(web_view, @"typeof __gCrWeb.print"));
83 EXPECT_NSEQ(@"undefined", web::ExecuteJavaScript(
84 web_view, @"typeof __gCrWeb.windowOpenFix"));
85 }
86
87 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/chrome_web_client.mm ('k') | ios/chrome/browser/web/chrome_web_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698