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