Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / chrome / common / chrome_content_client_unittest.cc
blob42514d7d9cd3eb31e77616737f38882591d0ea11
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.
5 #include "chrome/common/chrome_content_client.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_split.h"
9 #include "content/public/common/content_switches.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace {
14 void CheckUserAgentStringOrdering(bool mobile_device) {
15 std::vector<std::string> pieces;
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();
21 base::SplitStringUsingSubstr(buffer, "Mozilla/5.0 (", &pieces);
22 ASSERT_EQ(2u, pieces.size());
23 buffer = pieces[1];
24 EXPECT_EQ("", pieces[0]);
26 base::SplitStringUsingSubstr(buffer, ") AppleWebKit/", &pieces);
27 ASSERT_EQ(2u, pieces.size());
28 buffer = pieces[1];
29 std::string os_str = pieces[0];
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];
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];
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);
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);
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()));
59 } // namespace
62 namespace chrome_common {
64 TEST(ChromeContentClientTest, Basic) {
65 #if !defined(OS_ANDROID)
66 CheckUserAgentStringOrdering(false);
67 #else
68 const char* const kArguments[] = {"chrome"};
69 base::CommandLine::Reset();
70 base::CommandLine::Init(1, kArguments);
71 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
73 // Do it for regular devices.
74 ASSERT_FALSE(command_line->HasSwitch(switches::kUseMobileUserAgent));
75 CheckUserAgentStringOrdering(false);
77 // Do it for mobile devices.
78 command_line->AppendSwitch(switches::kUseMobileUserAgent);
79 ASSERT_TRUE(command_line->HasSwitch(switches::kUseMobileUserAgent));
80 CheckUserAgentStringOrdering(true);
81 #endif
84 } // namespace chrome_common