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

Side by Side Diff: chrome/common/chrome_content_client_unittest.cc

Issue 10854251: Allow the creation of partially spoofed user agents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reverted last patch set because of #ifdefed command line flag Created 8 years, 3 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "chrome/common/chrome_content_client.h"
6
7 #include "base/command_line.h"
8 #include "base/string_split.h"
9 #include "content/public/common/content_switches.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace chrome {
tony 2012/08/28 18:51:25 Nit: This should be in the chrome_common namespace
gone 2012/08/28 20:25:53 I've moved the test into the chrome_common::, but
13
14 void CheckUserAgentStringOrdering(bool mobile_device) {
tony 2012/08/28 18:51:25 Nit: Maybe use an anonymous namespace for this hel
gone 2012/08/28 20:25:53 Done.
15 std::vector<std::string> pieces;
16
17 // Check if the pieces of the user agent string come in the correct order.
18 ChromeContentClient content_client;
19 std::string buffer = content_client.GetUserAgent();
20
21 base::SplitStringUsingSubstr(buffer, "Mozilla/5.0 (", &pieces);
22 ASSERT_EQ(2u, pieces.size());
23 buffer = pieces[1];
24 EXPECT_EQ("", pieces[0]);
25
26 base::SplitStringUsingSubstr(buffer, ") AppleWebKit/", &pieces);
27 ASSERT_EQ(2u, pieces.size());
28 buffer = pieces[1];
29 std::string os_str = pieces[0];
30
31 base::SplitStringUsingSubstr(buffer, " (KHTML, like Gecko) ", &pieces);
32 ASSERT_EQ(2u, pieces.size());
33 buffer = pieces[1];
34 std::string webkit_version_str = pieces[0];
35
36 base::SplitStringUsingSubstr(buffer, " Safari/", &pieces);
37 ASSERT_EQ(2u, pieces.size());
38 std::string product_str = pieces[0];
39 std::string safari_version_str = pieces[1];
40
41 // Not sure what can be done to better check the OS string, since it's highly
42 // platform-dependent.
43 EXPECT_TRUE(os_str.size() > 0);
44
45 // Check that the version numbers match.
46 EXPECT_TRUE(webkit_version_str.size() > 0);
47 EXPECT_TRUE(safari_version_str.size() > 0);
48 EXPECT_EQ(webkit_version_str, safari_version_str);
49
50 EXPECT_EQ(0u, product_str.find("Chrome/"));
51 if (mobile_device) {
52 // "Mobile" gets tacked on to the end for mobile devices, like phones.
53 const std::string kMobileStr = " Mobile";
54 EXPECT_EQ(kMobileStr,
55 product_str.substr(product_str.size() - kMobileStr.size()));
56 }
57 }
58
59 TEST(ChromeContentClientTest, Basic) {
60 #if !defined(OS_ANDROID)
61 CheckUserAgentStringOrdering(false);
62 #else
63 // Do it once for mobile devices and once for other devices.
64 const char* kArguments[] = {"chrome"};
65 CommandLine* command_line = CommandLine::ForCurrentProcess();
66 command_line->Reset();
67 command_line->Init(1, kArguments);
68 ASSERT_FALSE(command_line->HasSwitch(switches::kUseMobileUserAgent));
69 CheckUserAgentStringOrdering(false);
70
71 command_line->AppendSwitch(switches::kUseMobileUserAgent);
72 ASSERT_TRUE(command_line->HasSwitch(switches::kUseMobileUserAgent));
73 CheckUserAgentStringOrdering(true);
74 #endif
75 }
76
77 };
OLDNEW
« no previous file with comments | « chrome/common/chrome_content_client.cc ('k') | content/browser/android/content_view_core_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698