[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1 | // Copyright 2013 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/browser/chrome_content_browser_client.h" |
| 6 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 7 | #include <map> |
| 8 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 9 | #include "base/command_line.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 11 | #include "base/metrics/field_trial.h" |
mpearson | 3c6d7af | 2015-05-13 23:59:53 | [diff] [blame] | 12 | #include "base/strings/utf_string_conversions.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 14 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
timvolodine | a47291a | 2015-01-23 14:04:43 | [diff] [blame] | 15 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
[email protected] | bf5c532d | 2014-07-05 00:29:53 | [diff] [blame] | 16 | #include "components/search_engines/template_url_service.h" |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 17 | #include "components/variations/entropy_provider.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 18 | #include "components/variations/variations_associated_data.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 19 | #include "components/version_info/version_info.h" |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 20 | #include "content/public/browser/navigation_controller.h" |
| 21 | #include "content/public/browser/navigation_entry.h" |
| 22 | #include "content/public/browser/web_contents.h" |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 23 | #include "content/public/common/content_switches.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 24 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 25 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 5f5ef80 | 2013-07-04 16:11:13 | [diff] [blame] | 26 | #include "url/gurl.h" |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 27 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame^] | 28 | #if !defined(OS_ANDROID) |
thestig | f8056446 | 2015-09-29 23:12:08 | [diff] [blame] | 29 | #include "chrome/browser/ui/browser.h" |
| 30 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 31 | #include "chrome/test/base/browser_with_test_window_test.h" |
| 32 | #include "chrome/test/base/search_test_utils.h" |
| 33 | #endif |
| 34 | |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 35 | using ChromeContentBrowserClientTest = testing::Test; |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 36 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 37 | TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) { |
| 38 | ChromeContentBrowserClient client; |
| 39 | EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test"))); |
| 40 | EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com"))); |
| 41 | EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com"))); |
| 42 | } |
| 43 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame^] | 44 | // BrowserWithTestWindowTest doesn't work on Android. |
| 45 | #if !defined(OS_ANDROID) |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 46 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 47 | using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest; |
| 48 | |
| 49 | static void DidOpenURLForWindowTest(content::WebContents** target_contents, |
| 50 | content::WebContents* opened_contents) { |
| 51 | DCHECK(target_contents); |
| 52 | |
| 53 | *target_contents = opened_contents; |
| 54 | } |
| 55 | |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 56 | // This test opens two URLs using ContentBrowserClient::OpenURL. It expects the |
| 57 | // URLs to be opened in new tabs and activated, changing the active tabs after |
| 58 | // each call and increasing the tab count by 2. |
| 59 | TEST_F(ChromeContentBrowserClientWindowTest, OpenURL) { |
| 60 | ChromeContentBrowserClient client; |
| 61 | |
| 62 | int previous_count = browser()->tab_strip_model()->count(); |
| 63 | |
| 64 | GURL urls[] = { GURL("https://www.google.com"), |
| 65 | GURL("https://www.chromium.org") }; |
| 66 | |
| 67 | for (const GURL& url : urls) { |
| 68 | content::OpenURLParams params(url, |
| 69 | content::Referrer(), |
| 70 | NEW_FOREGROUND_TAB, |
| 71 | ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 72 | false); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 73 | // TODO(peter): We should have more in-depth browser tests for the window |
| 74 | // opening functionality, which also covers Android. This test can currently |
| 75 | // only be ran on platforms where OpenURL is implemented synchronously. |
| 76 | // See https://crbug.com/457667. |
| 77 | content::WebContents* web_contents = nullptr; |
| 78 | client.OpenURL(browser()->profile(), |
| 79 | params, |
| 80 | base::Bind(&DidOpenURLForWindowTest, &web_contents)); |
| 81 | |
| 82 | EXPECT_TRUE(web_contents); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 83 | |
| 84 | content::WebContents* active_contents = browser()->tab_strip_model()-> |
| 85 | GetActiveWebContents(); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 86 | EXPECT_EQ(web_contents, active_contents); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 87 | EXPECT_EQ(url, active_contents->GetVisibleURL()); |
| 88 | } |
| 89 | |
| 90 | EXPECT_EQ(previous_count + 2, browser()->tab_strip_model()->count()); |
| 91 | } |
| 92 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame^] | 93 | #endif // !defined(OS_ANDROID) |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 94 | |
brettw | a68ea2b | 2015-02-01 02:54:07 | [diff] [blame] | 95 | #if defined(ENABLE_WEBRTC) |
| 96 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 97 | // NOTE: Any updates to the expectations in these tests should also be done in |
| 98 | // the browser test WebRtcDisableEncryptionFlagBrowserTest. |
| 99 | class DisableWebRtcEncryptionFlagTest : public testing::Test { |
| 100 | public: |
| 101 | DisableWebRtcEncryptionFlagTest() |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 102 | : from_command_line_(base::CommandLine::NO_PROGRAM), |
| 103 | to_command_line_(base::CommandLine::NO_PROGRAM) {} |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 104 | |
| 105 | protected: |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 106 | void SetUp() override { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 107 | from_command_line_.AppendSwitch(switches::kDisableWebRtcEncryption); |
| 108 | } |
| 109 | |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 110 | void MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel channel) { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 111 | ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
| 112 | &to_command_line_, |
| 113 | from_command_line_, |
| 114 | channel); |
| 115 | } |
| 116 | |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 117 | base::CommandLine from_command_line_; |
| 118 | base::CommandLine to_command_line_; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 119 | |
thestig | f8056446 | 2015-09-29 23:12:08 | [diff] [blame] | 120 | private: |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(DisableWebRtcEncryptionFlagTest); |
| 122 | }; |
| 123 | |
| 124 | TEST_F(DisableWebRtcEncryptionFlagTest, UnknownChannel) { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 125 | MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::UNKNOWN); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 126 | EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption)); |
| 127 | } |
| 128 | |
| 129 | TEST_F(DisableWebRtcEncryptionFlagTest, CanaryChannel) { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 130 | MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::CANARY); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 131 | EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption)); |
| 132 | } |
| 133 | |
| 134 | TEST_F(DisableWebRtcEncryptionFlagTest, DevChannel) { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 135 | MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::DEV); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 136 | EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption)); |
| 137 | } |
| 138 | |
| 139 | TEST_F(DisableWebRtcEncryptionFlagTest, BetaChannel) { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 140 | MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::BETA); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 141 | #if defined(OS_ANDROID) |
| 142 | EXPECT_TRUE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption)); |
| 143 | #else |
| 144 | EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption)); |
| 145 | #endif |
| 146 | } |
| 147 | |
| 148 | TEST_F(DisableWebRtcEncryptionFlagTest, StableChannel) { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 149 | MaybeCopyDisableWebRtcEncryptionSwitch(version_info::Channel::STABLE); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 150 | EXPECT_FALSE(to_command_line_.HasSwitch(switches::kDisableWebRtcEncryption)); |
| 151 | } |
| 152 | |
brettw | a68ea2b | 2015-02-01 02:54:07 | [diff] [blame] | 153 | #endif // ENABLE_WEBRTC |
| 154 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 155 | class BlinkSettingsFieldTrialTest : public testing::Test { |
| 156 | public: |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 157 | static const char kParserFieldTrialName[]; |
| 158 | static const char kIFrameFieldTrialName[]; |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 159 | static const char kResourcePrioritiesFieldTrialName[]; |
| 160 | static const char kFakeGroupName[]; |
| 161 | static const char kDefaultGroupName[]; |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 162 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 163 | BlinkSettingsFieldTrialTest() |
| 164 | : trial_list_(NULL), |
| 165 | command_line_(base::CommandLine::NO_PROGRAM) {} |
| 166 | |
| 167 | void SetUp() override { |
| 168 | command_line_.AppendSwitchASCII( |
| 169 | switches::kProcessType, switches::kRendererProcess); |
| 170 | } |
| 171 | |
| 172 | void TearDown() override { |
| 173 | variations::testing::ClearAllVariationParams(); |
| 174 | } |
| 175 | |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 176 | void CreateFieldTrial(const char* trial_name, const char* group_name) { |
| 177 | base::FieldTrialList::CreateFieldTrial(trial_name, group_name); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 178 | } |
| 179 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 180 | void CreateFieldTrialWithParams( |
| 181 | const char* trial_name, |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 182 | const char* group_name, |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 183 | const char* key1, const char* value1, |
| 184 | const char* key2, const char* value2) { |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 185 | std::map<std::string, std::string> params; |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 186 | params.insert(std::make_pair(key1, value1)); |
| 187 | params.insert(std::make_pair(key2, value2)); |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 188 | CreateFieldTrial(trial_name, kFakeGroupName); |
| 189 | variations::AssociateVariationParams(trial_name, kFakeGroupName, params); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void AppendContentBrowserClientSwitches() { |
| 193 | client_.AppendExtraCommandLineSwitches(&command_line_, kFakeChildProcessId); |
| 194 | } |
| 195 | |
| 196 | const base::CommandLine& command_line() const { |
| 197 | return command_line_; |
| 198 | } |
| 199 | |
| 200 | void AppendBlinkSettingsSwitch(const char* value) { |
| 201 | command_line_.AppendSwitchASCII(switches::kBlinkSettings, value); |
| 202 | } |
| 203 | |
| 204 | private: |
| 205 | static const int kFakeChildProcessId = 1; |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 206 | |
| 207 | ChromeContentBrowserClient client_; |
| 208 | base::FieldTrialList trial_list_; |
| 209 | base::CommandLine command_line_; |
| 210 | |
| 211 | content::TestBrowserThreadBundle thread_bundle_; |
| 212 | }; |
| 213 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 214 | const char BlinkSettingsFieldTrialTest::kParserFieldTrialName[] = |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 215 | "BackgroundHtmlParserTokenLimits"; |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 216 | const char BlinkSettingsFieldTrialTest::kIFrameFieldTrialName[] = |
| 217 | "LowPriorityIFrames"; |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 218 | const char BlinkSettingsFieldTrialTest::kResourcePrioritiesFieldTrialName[] = |
| 219 | "ResourcePriorities"; |
| 220 | const char BlinkSettingsFieldTrialTest::kFakeGroupName[] = "FakeGroup"; |
| 221 | const char BlinkSettingsFieldTrialTest::kDefaultGroupName[] = "Default"; |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 222 | |
| 223 | TEST_F(BlinkSettingsFieldTrialTest, NoFieldTrial) { |
| 224 | AppendContentBrowserClientSwitches(); |
| 225 | EXPECT_FALSE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 226 | } |
| 227 | |
| 228 | TEST_F(BlinkSettingsFieldTrialTest, FieldTrialWithoutParams) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 229 | CreateFieldTrial(kParserFieldTrialName, kFakeGroupName); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 230 | AppendContentBrowserClientSwitches(); |
| 231 | EXPECT_FALSE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 232 | } |
| 233 | |
| 234 | TEST_F(BlinkSettingsFieldTrialTest, BlinkSettingsSwitchAlreadySpecified) { |
| 235 | AppendBlinkSettingsSwitch("foo"); |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 236 | CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName, |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 237 | "key1", "value1", "key2", "value2"); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 238 | AppendContentBrowserClientSwitches(); |
| 239 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 240 | EXPECT_EQ("foo", |
| 241 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 242 | } |
| 243 | |
| 244 | TEST_F(BlinkSettingsFieldTrialTest, FieldTrialEnabled) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 245 | CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName, |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 246 | "key1", "value1", "key2", "value2"); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 247 | AppendContentBrowserClientSwitches(); |
| 248 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 249 | EXPECT_EQ("key1=value1,key2=value2", |
| 250 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 251 | } |
| 252 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 253 | TEST_F(BlinkSettingsFieldTrialTest, MultipleFieldTrialsEnabled) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 254 | CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName, |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 255 | "key1", "value1", "key2", "value2"); |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 256 | CreateFieldTrialWithParams(kIFrameFieldTrialName, kFakeGroupName, |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 257 | "keyA", "valueA", "keyB", "valueB"); |
| 258 | AppendContentBrowserClientSwitches(); |
| 259 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 260 | EXPECT_EQ("key1=value1,key2=value2,keyA=valueA,keyB=valueB", |
| 261 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 262 | } |
| 263 | |
| 264 | TEST_F(BlinkSettingsFieldTrialTest, MultipleFieldTrialsDuplicateKeys) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 265 | CreateFieldTrialWithParams(kParserFieldTrialName, kFakeGroupName, |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 266 | "key1", "value1", "key2", "value2"); |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 267 | CreateFieldTrialWithParams(kIFrameFieldTrialName, kFakeGroupName, |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 268 | "key2", "duplicate", "key3", "value3"); |
| 269 | AppendContentBrowserClientSwitches(); |
| 270 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 271 | EXPECT_EQ("key1=value1,key2=value2,key2=duplicate,key3=value3", |
| 272 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 273 | } |
| 274 | |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 275 | TEST_F(BlinkSettingsFieldTrialTest, ResourcePrioritiesDefault) { |
| 276 | CreateFieldTrial(kResourcePrioritiesFieldTrialName, kDefaultGroupName); |
| 277 | AppendContentBrowserClientSwitches(); |
| 278 | EXPECT_FALSE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 279 | } |
| 280 | |
| 281 | TEST_F(BlinkSettingsFieldTrialTest, ResourcePrioritiesEverythingEnabled) { |
| 282 | CreateFieldTrial(kResourcePrioritiesFieldTrialName, |
| 283 | "Everything_11111_1_1_10"); |
| 284 | AppendContentBrowserClientSwitches(); |
| 285 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 286 | EXPECT_EQ("fetchDeferLateScripts=true," |
| 287 | "fetchIncreaseFontPriority=true," |
| 288 | "fetchIncreaseAsyncScriptPriority=true," |
| 289 | "fetchIncreasePriorities=true", |
| 290 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 291 | } |
| 292 | |
| 293 | TEST_F(BlinkSettingsFieldTrialTest, ResourcePrioritiesDeferLateScripts) { |
| 294 | CreateFieldTrial(kResourcePrioritiesFieldTrialName, |
| 295 | "LateScripts_10000_0_1_10"); |
| 296 | AppendContentBrowserClientSwitches(); |
| 297 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 298 | EXPECT_EQ("fetchDeferLateScripts=true", |
| 299 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 300 | } |
| 301 | |
| 302 | TEST_F(BlinkSettingsFieldTrialTest, ResourcePrioritiesFontsEnabled) { |
| 303 | CreateFieldTrial(kResourcePrioritiesFieldTrialName, "FontOnly_01000_0_1_10"); |
| 304 | AppendContentBrowserClientSwitches(); |
| 305 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 306 | EXPECT_EQ("fetchIncreaseFontPriority=true", |
| 307 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 308 | } |
| 309 | |
| 310 | TEST_F(BlinkSettingsFieldTrialTest, ResourcePrioritiesIncreaseAsyncScript) { |
| 311 | CreateFieldTrial(kResourcePrioritiesFieldTrialName, |
| 312 | "AsyncScript_00100_0_1_10"); |
| 313 | AppendContentBrowserClientSwitches(); |
| 314 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 315 | EXPECT_EQ("fetchIncreaseAsyncScriptPriority=true", |
| 316 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 317 | } |
| 318 | |
| 319 | TEST_F(BlinkSettingsFieldTrialTest, ResourcePrioritiesIncreasePriorities) { |
| 320 | CreateFieldTrial(kResourcePrioritiesFieldTrialName, |
| 321 | "IncreasePriorities_00010_0_1_10"); |
| 322 | AppendContentBrowserClientSwitches(); |
| 323 | EXPECT_TRUE(command_line().HasSwitch(switches::kBlinkSettings)); |
| 324 | EXPECT_EQ("fetchIncreasePriorities=true", |
| 325 | command_line().GetSwitchValueASCII(switches::kBlinkSettings)); |
| 326 | } |
| 327 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame^] | 328 | #if !defined(OS_ANDROID) |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 329 | namespace content { |
| 330 | |
| 331 | class InstantNTPURLRewriteTest : public BrowserWithTestWindowTest { |
| 332 | protected: |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 333 | void SetUp() override { |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 334 | BrowserWithTestWindowTest::SetUp(); |
| 335 | field_trial_list_.reset(new base::FieldTrialList( |
| 336 | new metrics::SHA1EntropyProvider("42"))); |
| 337 | } |
| 338 | |
| 339 | void InstallTemplateURLWithNewTabPage(GURL new_tab_page_url) { |
| 340 | TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 341 | profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 342 | TemplateURLService* template_url_service = |
| 343 | TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
thestig | f8056446 | 2015-09-29 23:12:08 | [diff] [blame] | 344 | search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 345 | |
| 346 | TemplateURLData data; |
mpearson | 3c6d7af | 2015-05-13 23:59:53 | [diff] [blame] | 347 | data.SetShortName(base::ASCIIToUTF16("foo.com")); |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 348 | data.SetURL("http://foo.com/url?bar={searchTerms}"); |
| 349 | data.new_tab_url = new_tab_page_url.spec(); |
[email protected] | 168d0872 | 2014-06-18 07:13:28 | [diff] [blame] | 350 | TemplateURL* template_url = new TemplateURL(data); |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 351 | // Takes ownership. |
| 352 | template_url_service->Add(template_url); |
[email protected] | f1cb558 | 2014-04-25 07:35:26 | [diff] [blame] | 353 | template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
[email protected] | 10a9bf9 | 2013-11-13 23:34:48 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 357 | }; |
| 358 | |
| 359 | TEST_F(InstantNTPURLRewriteTest, UberURLHandler_InstantExtendedNewTabPage) { |
| 360 | const GURL url_original("chrome://newtab"); |
| 361 | const GURL url_rewritten("https://www.example.com/newtab"); |
| 362 | InstallTemplateURLWithNewTabPage(url_rewritten); |
| 363 | ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", |
| 364 | "Group1 use_cacheable_ntp:1")); |
| 365 | |
| 366 | AddTab(browser(), GURL("chrome://blank")); |
| 367 | NavigateAndCommitActiveTab(url_original); |
| 368 | |
| 369 | NavigationEntry* entry = browser()->tab_strip_model()-> |
| 370 | GetActiveWebContents()->GetController().GetLastCommittedEntry(); |
| 371 | ASSERT_TRUE(entry != NULL); |
| 372 | EXPECT_EQ(url_rewritten, entry->GetURL()); |
| 373 | EXPECT_EQ(url_original, entry->GetVirtualURL()); |
| 374 | } |
| 375 | |
| 376 | } // namespace content |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame^] | 377 | #endif // !defined(OS_ANDROID) |