OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/string_number_conversions.h" |
6 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" |
8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" | 10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 11 #include "chrome/browser/extensions/extension_function_test_utils.h" |
10 #include "chrome/browser/extensions/extension_message_bubble.h" | 12 #include "chrome/browser/extensions/extension_message_bubble.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h" | 14 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h" |
| 15 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h" |
13 #include "chrome/browser/extensions/settings_api_bubble_controller.h" | 16 #include "chrome/browser/extensions/settings_api_bubble_controller.h" |
14 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" | 17 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" |
15 #include "chrome/browser/extensions/test_extension_system.h" | 18 #include "chrome/browser/extensions/test_extension_system.h" |
16 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 20 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "extensions/browser/extension_pref_value_map.h" |
| 24 #include "extensions/browser/extension_pref_value_map_factory.h" |
19 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 26 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
21 #include "extensions/common/extension_builder.h" | 28 #include "extensions/common/extension_builder.h" |
22 #include "extensions/common/feature_switch.h" | 29 #include "extensions/common/feature_switch.h" |
| 30 #include "extensions/common/value_builder.h" |
23 | 31 |
24 namespace { | 32 namespace { |
25 | 33 |
26 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; | 34 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; |
27 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; | 35 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; |
28 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; | 36 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; |
29 | 37 |
30 } // namespace | 38 } // namespace |
31 | 39 |
32 namespace extensions { | 40 namespace extensions { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 ++dismiss_button_callback_count_; | 160 ++dismiss_button_callback_count_; |
153 NtpOverriddenBubbleController::OnBubbleDismiss(); | 161 NtpOverriddenBubbleController::OnBubbleDismiss(); |
154 } | 162 } |
155 | 163 |
156 virtual void OnLinkClicked() OVERRIDE { | 164 virtual void OnLinkClicked() OVERRIDE { |
157 ++link_click_callback_count_; | 165 ++link_click_callback_count_; |
158 NtpOverriddenBubbleController::OnLinkClicked(); | 166 NtpOverriddenBubbleController::OnLinkClicked(); |
159 } | 167 } |
160 }; | 168 }; |
161 | 169 |
| 170 // A test class for the ProxyOverriddenBubbleController. |
| 171 class TestProxyOverriddenBubbleController |
| 172 : public ProxyOverriddenBubbleController, |
| 173 public TestDelegate { |
| 174 public: |
| 175 explicit TestProxyOverriddenBubbleController(Profile* profile) |
| 176 : ProxyOverriddenBubbleController(profile) { |
| 177 } |
| 178 |
| 179 virtual void OnBubbleAction() OVERRIDE { |
| 180 ++action_button_callback_count_; |
| 181 ProxyOverriddenBubbleController::OnBubbleAction(); |
| 182 } |
| 183 |
| 184 virtual void OnBubbleDismiss() OVERRIDE { |
| 185 ++dismiss_button_callback_count_; |
| 186 ProxyOverriddenBubbleController::OnBubbleDismiss(); |
| 187 } |
| 188 |
| 189 virtual void OnLinkClicked() OVERRIDE { |
| 190 ++link_click_callback_count_; |
| 191 ProxyOverriddenBubbleController::OnLinkClicked(); |
| 192 } |
| 193 }; |
| 194 |
162 // A fake bubble used for testing the controller. Takes an action that specifies | 195 // A fake bubble used for testing the controller. Takes an action that specifies |
163 // what should happen when the bubble is "shown" (the bubble is actually not | 196 // what should happen when the bubble is "shown" (the bubble is actually not |
164 // shown, the corresponding action is taken immediately). | 197 // shown, the corresponding action is taken immediately). |
165 class FakeExtensionMessageBubble : public ExtensionMessageBubble { | 198 class FakeExtensionMessageBubble : public ExtensionMessageBubble { |
166 public: | 199 public: |
167 enum ExtensionBubbleAction { | 200 enum ExtensionBubbleAction { |
168 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, | 201 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, |
169 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, | 202 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, |
170 BUBBLE_ACTION_CLICK_LINK, | 203 BUBBLE_ACTION_CLICK_LINK, |
171 }; | 204 }; |
(...skipping 30 matching lines...) Expand all Loading... |
202 | 235 |
203 base::Closure action_callback_; | 236 base::Closure action_callback_; |
204 base::Closure dismiss_callback_; | 237 base::Closure dismiss_callback_; |
205 base::Closure link_callback_; | 238 base::Closure link_callback_; |
206 }; | 239 }; |
207 | 240 |
208 class ExtensionMessageBubbleTest : public testing::Test { | 241 class ExtensionMessageBubbleTest : public testing::Test { |
209 public: | 242 public: |
210 ExtensionMessageBubbleTest() {} | 243 ExtensionMessageBubbleTest() {} |
211 | 244 |
212 void LoadGenericExtension(const std::string& index, | 245 testing::AssertionResult LoadGenericExtension(const std::string& index, |
213 const std::string& id, | 246 const std::string& id, |
214 Manifest::Location location) { | 247 Manifest::Location location) { |
215 extensions::ExtensionBuilder builder; | 248 ExtensionBuilder builder; |
216 builder.SetManifest(extensions::DictionaryBuilder() | 249 builder.SetManifest(DictionaryBuilder() |
217 .Set("name", std::string("Extension " + index)) | 250 .Set("name", std::string("Extension " + index)) |
218 .Set("version", "1.0") | 251 .Set("version", "1.0") |
219 .Set("manifest_version", 2)); | 252 .Set("manifest_version", 2)); |
220 builder.SetLocation(location); | 253 builder.SetLocation(location); |
221 builder.SetID(id); | 254 builder.SetID(id); |
222 service_->AddExtension(builder.Build().get()); | 255 service_->AddExtension(builder.Build().get()); |
| 256 |
| 257 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) |
| 258 return testing::AssertionSuccess(); |
| 259 return testing::AssertionFailure() << "Could not install extension: " << id; |
223 } | 260 } |
224 | 261 |
225 void LoadExtensionWithAction(const std::string& index, | 262 testing::AssertionResult LoadExtensionWithAction( |
226 const std::string& id, | 263 const std::string& index, |
227 Manifest::Location location) { | 264 const std::string& id, |
228 extensions::ExtensionBuilder builder; | 265 Manifest::Location location) { |
229 builder.SetManifest(extensions::DictionaryBuilder() | 266 ExtensionBuilder builder; |
| 267 builder.SetManifest(DictionaryBuilder() |
230 .Set("name", std::string("Extension " + index)) | 268 .Set("name", std::string("Extension " + index)) |
231 .Set("version", "1.0") | 269 .Set("version", "1.0") |
232 .Set("manifest_version", 2) | 270 .Set("manifest_version", 2) |
233 .Set("browser_action", | 271 .Set("browser_action", |
234 extensions::DictionaryBuilder().Set( | 272 DictionaryBuilder().Set( |
235 "default_title", "Default title"))); | 273 "default_title", "Default title"))); |
236 builder.SetLocation(location); | 274 builder.SetLocation(location); |
237 builder.SetID(id); | 275 builder.SetID(id); |
238 service_->AddExtension(builder.Build().get()); | 276 service_->AddExtension(builder.Build().get()); |
| 277 |
| 278 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) |
| 279 return testing::AssertionSuccess(); |
| 280 return testing::AssertionFailure() << "Could not install extension: " << id; |
239 } | 281 } |
240 | 282 |
241 void LoadExtensionOverridingHome(const std::string& index, | 283 testing::AssertionResult LoadExtensionOverridingHome( |
242 const std::string& id, | 284 const std::string& index, |
243 Manifest::Location location) { | 285 const std::string& id, |
244 extensions::ExtensionBuilder builder; | 286 Manifest::Location location) { |
245 builder.SetManifest(extensions::DictionaryBuilder() | 287 ExtensionBuilder builder; |
| 288 builder.SetManifest(DictionaryBuilder() |
246 .Set("name", std::string("Extension " + index)) | 289 .Set("name", std::string("Extension " + index)) |
247 .Set("version", "1.0") | 290 .Set("version", "1.0") |
248 .Set("manifest_version", 2) | 291 .Set("manifest_version", 2) |
249 .Set("chrome_settings_overrides", | 292 .Set("chrome_settings_overrides", |
250 extensions::DictionaryBuilder().Set( | 293 DictionaryBuilder().Set( |
251 "homepage", "http://www.google.com"))); | 294 "homepage", "http://www.google.com"))); |
252 builder.SetLocation(location); | 295 builder.SetLocation(location); |
253 builder.SetID(id); | 296 builder.SetID(id); |
254 service_->AddExtension(builder.Build().get()); | 297 service_->AddExtension(builder.Build().get()); |
| 298 |
| 299 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) |
| 300 return testing::AssertionSuccess(); |
| 301 return testing::AssertionFailure() << "Could not install extension: " << id; |
255 } | 302 } |
256 | 303 |
257 void LoadExtensionOverridingStart(const std::string& index, | 304 testing::AssertionResult LoadExtensionOverridingStart( |
258 const std::string& id, | 305 const std::string& index, |
259 Manifest::Location location) { | 306 const std::string& id, |
260 extensions::ExtensionBuilder builder; | 307 Manifest::Location location) { |
261 builder.SetManifest(extensions::DictionaryBuilder() | 308 ExtensionBuilder builder; |
| 309 builder.SetManifest(DictionaryBuilder() |
262 .Set("name", std::string("Extension " + index)) | 310 .Set("name", std::string("Extension " + index)) |
263 .Set("version", "1.0") | 311 .Set("version", "1.0") |
264 .Set("manifest_version", 2) | 312 .Set("manifest_version", 2) |
265 .Set("chrome_settings_overrides", | 313 .Set("chrome_settings_overrides", |
266 extensions::DictionaryBuilder().Set( | 314 DictionaryBuilder().Set( |
267 "startup_pages", | 315 "startup_pages", |
268 extensions::ListBuilder().Append( | 316 ListBuilder().Append( |
269 "http://www.google.com")))); | 317 "http://www.google.com")))); |
270 builder.SetLocation(location); | 318 builder.SetLocation(location); |
271 builder.SetID(id); | 319 builder.SetID(id); |
272 service_->AddExtension(builder.Build().get()); | 320 service_->AddExtension(builder.Build().get()); |
| 321 |
| 322 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) |
| 323 return testing::AssertionSuccess(); |
| 324 return testing::AssertionFailure() << "Could not install extension: " << id; |
273 } | 325 } |
274 | 326 |
275 void LoadExtensionOverridingNtp(const std::string& index, | 327 testing::AssertionResult LoadExtensionOverridingNtp( |
276 const std::string& id, | 328 const std::string& index, |
277 Manifest::Location location) { | 329 const std::string& id, |
278 extensions::ExtensionBuilder builder; | 330 Manifest::Location location) { |
279 builder.SetManifest(extensions::DictionaryBuilder() | 331 ExtensionBuilder builder; |
| 332 builder.SetManifest(DictionaryBuilder() |
280 .Set("name", std::string("Extension " + index)) | 333 .Set("name", std::string("Extension " + index)) |
281 .Set("version", "1.0") | 334 .Set("version", "1.0") |
282 .Set("manifest_version", 2) | 335 .Set("manifest_version", 2) |
283 .Set("chrome_url_overrides", | 336 .Set("chrome_url_overrides", |
284 extensions::DictionaryBuilder().Set( | 337 DictionaryBuilder().Set( |
285 "newtab", "Default.html"))); | 338 "newtab", "Default.html"))); |
286 | 339 |
287 builder.SetLocation(location); | 340 builder.SetLocation(location); |
288 builder.SetID(id); | 341 builder.SetID(id); |
289 service_->AddExtension(builder.Build().get()); | 342 service_->AddExtension(builder.Build().get()); |
| 343 |
| 344 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) |
| 345 return testing::AssertionSuccess(); |
| 346 return testing::AssertionFailure() << "Could not install extension: " << id; |
| 347 } |
| 348 |
| 349 testing::AssertionResult LoadExtensionOverridingProxy( |
| 350 const std::string& index, |
| 351 const std::string& id, |
| 352 Manifest::Location location) { |
| 353 ExtensionBuilder builder; |
| 354 builder.SetManifest(DictionaryBuilder() |
| 355 .Set("name", std::string("Extension " + index)) |
| 356 .Set("version", "1.0") |
| 357 .Set("manifest_version", 2) |
| 358 .Set("permissions", |
| 359 ListBuilder().Append("proxy"))); |
| 360 |
| 361 builder.SetLocation(location); |
| 362 builder.SetID(id); |
| 363 service_->AddExtension(builder.Build().get()); |
| 364 |
| 365 // The proxy check relies on ExtensionPrefValueMap being up to date as to |
| 366 // specifying which extension is controlling the proxy, but unfortunately |
| 367 // that Map is not updated automatically for unit tests, so we simulate the |
| 368 // update here to avoid test failures. |
| 369 ExtensionPrefValueMap* extension_prefs_value_map = |
| 370 ExtensionPrefValueMapFactory::GetForBrowserContext(profile()); |
| 371 extension_prefs_value_map->RegisterExtension( |
| 372 id, |
| 373 base::Time::Now(), |
| 374 true, // is_enabled. |
| 375 false); // is_incognito_enabled. |
| 376 extension_prefs_value_map->SetExtensionPref( |
| 377 id, |
| 378 prefs::kProxy, |
| 379 kExtensionPrefsScopeRegular, |
| 380 base::Value::CreateStringValue(id)); |
| 381 |
| 382 if (ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(id)) |
| 383 return testing::AssertionSuccess(); |
| 384 return testing::AssertionFailure() << "Could not install extension: " << id; |
290 } | 385 } |
291 | 386 |
292 void Init() { | 387 void Init() { |
293 // The two lines of magical incantation required to get the extension | 388 // The two lines of magical incantation required to get the extension |
294 // service to work inside a unit test and access the extension prefs. | 389 // service to work inside a unit test and access the extension prefs. |
295 thread_bundle_.reset(new content::TestBrowserThreadBundle); | 390 thread_bundle_.reset(new content::TestBrowserThreadBundle); |
296 profile_.reset(new TestingProfile); | 391 profile_.reset(new TestingProfile); |
297 static_cast<TestExtensionSystem*>( | 392 static_cast<TestExtensionSystem*>( |
298 ExtensionSystem::Get(profile()))->CreateExtensionService( | 393 ExtensionSystem::Get(profile()))->CreateExtensionService( |
299 CommandLine::ForCurrentProcess(), | 394 CommandLine::ForCurrentProcess(), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 #if defined(OS_WIN) | 436 #if defined(OS_WIN) |
342 #define MAYBE_WipeoutControllerTest WipeoutControllerTest | 437 #define MAYBE_WipeoutControllerTest WipeoutControllerTest |
343 #else | 438 #else |
344 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest | 439 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest |
345 #endif | 440 #endif |
346 | 441 |
347 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) { | 442 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) { |
348 Init(); | 443 Init(); |
349 // Add three extensions, and control two of them in this test (extension 1 | 444 // Add three extensions, and control two of them in this test (extension 1 |
350 // and 2). | 445 // and 2). |
351 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE); | 446 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); |
352 LoadGenericExtension("2", kId2, Manifest::UNPACKED); | 447 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); |
353 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY); | 448 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); |
354 | 449 |
355 scoped_ptr<TestSuspiciousExtensionBubbleController> controller( | 450 scoped_ptr<TestSuspiciousExtensionBubbleController> controller( |
356 new TestSuspiciousExtensionBubbleController(profile())); | 451 new TestSuspiciousExtensionBubbleController(profile())); |
357 FakeExtensionMessageBubble bubble; | 452 FakeExtensionMessageBubble bubble; |
358 bubble.set_action_on_show( | 453 bubble.set_action_on_show( |
359 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 454 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
360 | 455 |
361 // Validate that we don't have a suppress value for the extensions. | 456 // Validate that we don't have a suppress value for the extensions. |
362 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 457 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
363 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); | 458 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest | 513 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest |
419 #endif | 514 #endif |
420 | 515 |
421 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) { | 516 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) { |
422 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( | 517 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( |
423 FeatureSwitch::force_dev_mode_highlighting(), true); | 518 FeatureSwitch::force_dev_mode_highlighting(), true); |
424 Init(); | 519 Init(); |
425 // Add three extensions, and control two of them in this test (extension 1 | 520 // Add three extensions, and control two of them in this test (extension 1 |
426 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it | 521 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it |
427 // counts as a DevMode extension. | 522 // counts as a DevMode extension. |
428 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE); | 523 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); |
429 LoadGenericExtension("2", kId2, Manifest::UNPACKED); | 524 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); |
430 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY); | 525 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); |
431 | 526 |
432 scoped_ptr<TestDevModeBubbleController> controller( | 527 scoped_ptr<TestDevModeBubbleController> controller( |
433 new TestDevModeBubbleController(profile())); | 528 new TestDevModeBubbleController(profile())); |
434 | 529 |
435 // The list will contain one enabled unpacked extension. | 530 // The list will contain one enabled unpacked extension. |
436 EXPECT_TRUE(controller->ShouldShow()); | 531 EXPECT_TRUE(controller->ShouldShow()); |
437 std::vector<base::string16> dev_mode_extensions = | 532 std::vector<base::string16> dev_mode_extensions = |
438 controller->GetExtensionList(); | 533 controller->GetExtensionList(); |
439 ASSERT_EQ(2U, dev_mode_extensions.size()); | 534 ASSERT_EQ(2U, dev_mode_extensions.size()); |
440 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); | 535 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); |
441 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); | 536 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); |
442 EXPECT_EQ(0U, controller->link_click_count()); | 537 EXPECT_EQ(0U, controller->link_click_count()); |
443 EXPECT_EQ(0U, controller->dismiss_click_count()); | 538 EXPECT_EQ(0U, controller->dismiss_click_count()); |
444 EXPECT_EQ(0U, controller->action_click_count()); | 539 EXPECT_EQ(0U, controller->action_click_count()); |
445 | 540 |
446 // Simulate showing the bubble. | 541 // Simulate showing the bubble. |
447 FakeExtensionMessageBubble bubble; | 542 FakeExtensionMessageBubble bubble; |
448 bubble.set_action_on_show( | 543 bubble.set_action_on_show( |
449 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 544 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
450 controller->Show(&bubble); | 545 controller->Show(&bubble); |
451 EXPECT_EQ(0U, controller->link_click_count()); | 546 EXPECT_EQ(0U, controller->link_click_count()); |
452 EXPECT_EQ(0U, controller->action_click_count()); | 547 EXPECT_EQ(0U, controller->action_click_count()); |
453 EXPECT_EQ(1U, controller->dismiss_click_count()); | 548 EXPECT_EQ(1U, controller->dismiss_click_count()); |
454 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 549 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
455 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 550 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
| 551 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
456 | 552 |
457 // Do it again, but now press different button (Disable). | 553 // Do it again, but now press different button (Disable). |
458 bubble.set_action_on_show( | 554 bubble.set_action_on_show( |
459 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | 555 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
460 controller.reset(new TestDevModeBubbleController( | 556 controller.reset(new TestDevModeBubbleController( |
461 profile())); | 557 profile())); |
462 DevModeBubbleController::ClearProfileListForTesting(); | 558 DevModeBubbleController::ClearProfileListForTesting(); |
463 EXPECT_TRUE(controller->ShouldShow()); | 559 EXPECT_TRUE(controller->ShouldShow()); |
464 dev_mode_extensions = controller->GetExtensionList(); | 560 dev_mode_extensions = controller->GetExtensionList(); |
465 EXPECT_EQ(2U, dev_mode_extensions.size()); | 561 EXPECT_EQ(2U, dev_mode_extensions.size()); |
466 controller->Show(&bubble); // Simulate showing the bubble. | 562 controller->Show(&bubble); // Simulate showing the bubble. |
467 EXPECT_EQ(0U, controller->link_click_count()); | 563 EXPECT_EQ(0U, controller->link_click_count()); |
468 EXPECT_EQ(1U, controller->action_click_count()); | 564 EXPECT_EQ(1U, controller->action_click_count()); |
469 EXPECT_EQ(0U, controller->dismiss_click_count()); | 565 EXPECT_EQ(0U, controller->dismiss_click_count()); |
470 EXPECT_TRUE(service_->GetExtensionById(kId1, false) == NULL); | 566 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId1) != NULL); |
471 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); | 567 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); |
472 | 568 |
473 // Re-enable the extensions (disabled by the action button above). | 569 // Re-enable the extensions (disabled by the action button above). |
474 service_->EnableExtension(kId1); | 570 service_->EnableExtension(kId1); |
475 service_->EnableExtension(kId2); | 571 service_->EnableExtension(kId2); |
476 | 572 |
477 // Show the dialog a third time, but now press the learn more link. | 573 // Show the dialog a third time, but now press the learn more link. |
478 bubble.set_action_on_show( | 574 bubble.set_action_on_show( |
479 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 575 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
480 controller.reset(new TestDevModeBubbleController( | 576 controller.reset(new TestDevModeBubbleController( |
481 profile())); | 577 profile())); |
482 DevModeBubbleController::ClearProfileListForTesting(); | 578 DevModeBubbleController::ClearProfileListForTesting(); |
483 EXPECT_TRUE(controller->ShouldShow()); | 579 EXPECT_TRUE(controller->ShouldShow()); |
484 dev_mode_extensions = controller->GetExtensionList(); | 580 dev_mode_extensions = controller->GetExtensionList(); |
485 EXPECT_EQ(2U, dev_mode_extensions.size()); | 581 EXPECT_EQ(2U, dev_mode_extensions.size()); |
486 controller->Show(&bubble); // Simulate showing the bubble. | 582 controller->Show(&bubble); // Simulate showing the bubble. |
487 EXPECT_EQ(1U, controller->link_click_count()); | 583 EXPECT_EQ(1U, controller->link_click_count()); |
488 EXPECT_EQ(0U, controller->action_click_count()); | 584 EXPECT_EQ(0U, controller->action_click_count()); |
489 EXPECT_EQ(0U, controller->dismiss_click_count()); | 585 EXPECT_EQ(0U, controller->dismiss_click_count()); |
490 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 586 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
491 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 587 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
492 | 588 |
493 // Now disable the unpacked extension. | 589 // Now disable the unpacked extension. |
494 service_->DisableExtension(kId1, Extension::DISABLE_USER_ACTION); | 590 service_->DisableExtension(kId1, Extension::DISABLE_USER_ACTION); |
495 service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION); | 591 service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION); |
496 | 592 |
497 controller.reset(new TestDevModeBubbleController( | 593 controller.reset(new TestDevModeBubbleController( |
498 profile())); | 594 profile())); |
499 DevModeBubbleController::ClearProfileListForTesting(); | 595 DevModeBubbleController::ClearProfileListForTesting(); |
500 EXPECT_FALSE(controller->ShouldShow()); | 596 EXPECT_FALSE(controller->ShouldShow()); |
501 dev_mode_extensions = controller->GetExtensionList(); | 597 dev_mode_extensions = controller->GetExtensionList(); |
502 EXPECT_EQ(0U, dev_mode_extensions.size()); | 598 EXPECT_EQ(0U, dev_mode_extensions.size()); |
503 } | 599 } |
504 | 600 |
505 // The feature this is meant to test is only implemented on Windows. | 601 // The feature this is meant to test is only implemented on Windows. |
506 #if defined(OS_WIN) | 602 #if defined(OS_WIN) |
507 #define MAYBE_SettingsApiControllerTest SettingsApiControllerTest | 603 #define MAYBE_SettingsApiControllerTest SettingsApiControllerTest |
508 #else | 604 #else |
509 #define MAYBE_SettingsApiControllerTest DISABLED_SettingsApiControllerTest | 605 #define MAYBE_SettingsApiControllerTest DISABLED_SettingsApiControllerTest |
510 #endif | 606 #endif |
511 | 607 |
512 TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { | 608 TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { |
513 Init(); | 609 Init(); |
514 extensions::ExtensionPrefs* prefs = | 610 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
515 extensions::ExtensionPrefs::Get(profile()); | |
516 | 611 |
517 for (int i = 0; i < 3; ++i) { | 612 for (int i = 0; i < 3; ++i) { |
518 switch (static_cast<SettingsApiOverrideType>(i)) { | 613 switch (static_cast<SettingsApiOverrideType>(i)) { |
519 case BUBBLE_TYPE_HOME_PAGE: | 614 case BUBBLE_TYPE_HOME_PAGE: |
520 // Load two extensions overriding home page and one overriding something | 615 // Load two extensions overriding home page and one overriding something |
521 // unrelated (to check for interference). Extension 2 should still win | 616 // unrelated (to check for interference). Extension 2 should still win |
522 // on the home page setting. | 617 // on the home page setting. |
523 LoadExtensionOverridingHome("1", kId1, Manifest::UNPACKED); | 618 ASSERT_TRUE(LoadExtensionOverridingHome("1", kId1, Manifest::UNPACKED)); |
524 LoadExtensionOverridingHome("2", kId2, Manifest::UNPACKED); | 619 ASSERT_TRUE(LoadExtensionOverridingHome("2", kId2, Manifest::UNPACKED)); |
525 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED); | 620 ASSERT_TRUE( |
| 621 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); |
526 break; | 622 break; |
527 case BUBBLE_TYPE_SEARCH_ENGINE: | 623 case BUBBLE_TYPE_SEARCH_ENGINE: |
528 // We deliberately skip testing the search engine since it relies on | 624 // We deliberately skip testing the search engine since it relies on |
529 // TemplateURLServiceFactory that isn't available while unit testing. | 625 // TemplateURLServiceFactory that isn't available while unit testing. |
530 // This test is only simulating the bubble interaction with the user and | 626 // This test is only simulating the bubble interaction with the user and |
531 // that is more or less the same for the search engine as it is for the | 627 // that is more or less the same for the search engine as it is for the |
532 // others. | 628 // others. |
533 continue; | 629 continue; |
534 case BUBBLE_TYPE_STARTUP_PAGES: | 630 case BUBBLE_TYPE_STARTUP_PAGES: |
535 // Load two extensions overriding start page and one overriding | 631 // Load two extensions overriding start page and one overriding |
536 // something unrelated (to check for interference). Extension 2 should | 632 // something unrelated (to check for interference). Extension 2 should |
537 // still win on the startup page setting. | 633 // still win on the startup page setting. |
538 LoadExtensionOverridingStart("1", kId1, Manifest::UNPACKED); | 634 ASSERT_TRUE( |
539 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED); | 635 LoadExtensionOverridingStart("1", kId1, Manifest::UNPACKED)); |
540 LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED); | 636 ASSERT_TRUE( |
| 637 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED)); |
| 638 ASSERT_TRUE(LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED)); |
541 break; | 639 break; |
542 default: | 640 default: |
543 NOTREACHED(); | 641 NOTREACHED(); |
544 break; | 642 break; |
545 } | 643 } |
546 | 644 |
547 scoped_ptr<TestSettingsApiBubbleController> controller( | 645 scoped_ptr<TestSettingsApiBubbleController> controller( |
548 new TestSettingsApiBubbleController( | 646 new TestSettingsApiBubbleController( |
549 profile(), static_cast<SettingsApiOverrideType>(i))); | 647 profile(), static_cast<SettingsApiOverrideType>(i))); |
550 | 648 |
(...skipping 10 matching lines...) Expand all Loading... |
561 | 659 |
562 // Simulate showing the bubble and dismissing it. | 660 // Simulate showing the bubble and dismissing it. |
563 FakeExtensionMessageBubble bubble; | 661 FakeExtensionMessageBubble bubble; |
564 bubble.set_action_on_show( | 662 bubble.set_action_on_show( |
565 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 663 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
566 controller->Show(&bubble); | 664 controller->Show(&bubble); |
567 EXPECT_EQ(0U, controller->link_click_count()); | 665 EXPECT_EQ(0U, controller->link_click_count()); |
568 EXPECT_EQ(0U, controller->action_click_count()); | 666 EXPECT_EQ(0U, controller->action_click_count()); |
569 EXPECT_EQ(1U, controller->dismiss_click_count()); | 667 EXPECT_EQ(1U, controller->dismiss_click_count()); |
570 // No extension should have become disabled. | 668 // No extension should have become disabled. |
571 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 669 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
572 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 670 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
573 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 671 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
| 672 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
574 // Only extension 2 should have been acknowledged. | 673 // Only extension 2 should have been acknowledged. |
575 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); | 674 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
576 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); | 675 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
577 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); | 676 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
578 // Clean up after ourselves. | 677 // Clean up after ourselves. |
579 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); | 678 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); |
580 | 679 |
581 // Simulate clicking the learn more link to dismiss it. | 680 // Simulate clicking the learn more link to dismiss it. |
582 bubble.set_action_on_show( | 681 bubble.set_action_on_show( |
583 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 682 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
584 controller.reset(new TestSettingsApiBubbleController( | 683 controller.reset(new TestSettingsApiBubbleController( |
585 profile(), static_cast<SettingsApiOverrideType>(i))); | 684 profile(), static_cast<SettingsApiOverrideType>(i))); |
586 controller->Show(&bubble); | 685 controller->Show(&bubble); |
587 EXPECT_EQ(1U, controller->link_click_count()); | 686 EXPECT_EQ(1U, controller->link_click_count()); |
588 EXPECT_EQ(0U, controller->action_click_count()); | 687 EXPECT_EQ(0U, controller->action_click_count()); |
589 EXPECT_EQ(0U, controller->dismiss_click_count()); | 688 EXPECT_EQ(0U, controller->dismiss_click_count()); |
590 // No extension should have become disabled. | 689 // No extension should have become disabled. |
591 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 690 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
592 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 691 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
593 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 692 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
594 // Only extension 2 should have been acknowledged. | 693 // Only extension 2 should have been acknowledged. |
595 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); | 694 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
596 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); | 695 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
597 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); | 696 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
598 // Clean up after ourselves. | 697 // Clean up after ourselves. |
599 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); | 698 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); |
600 | 699 |
601 // Do it again, but now opt to disable the extension. | 700 // Do it again, but now opt to disable the extension. |
602 bubble.set_action_on_show( | 701 bubble.set_action_on_show( |
603 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | 702 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
604 controller.reset(new TestSettingsApiBubbleController( | 703 controller.reset(new TestSettingsApiBubbleController( |
605 profile(), static_cast<SettingsApiOverrideType>(i))); | 704 profile(), static_cast<SettingsApiOverrideType>(i))); |
606 EXPECT_TRUE(controller->ShouldShow(kId2)); | 705 EXPECT_TRUE(controller->ShouldShow(kId2)); |
607 override_extensions = controller->GetExtensionList(); | 706 override_extensions = controller->GetExtensionList(); |
608 EXPECT_EQ(1U, override_extensions.size()); | 707 EXPECT_EQ(1U, override_extensions.size()); |
609 controller->Show(&bubble); // Simulate showing the bubble. | 708 controller->Show(&bubble); // Simulate showing the bubble. |
610 EXPECT_EQ(0U, controller->link_click_count()); | 709 EXPECT_EQ(0U, controller->link_click_count()); |
611 EXPECT_EQ(1U, controller->action_click_count()); | 710 EXPECT_EQ(1U, controller->action_click_count()); |
612 EXPECT_EQ(0U, controller->dismiss_click_count()); | 711 EXPECT_EQ(0U, controller->dismiss_click_count()); |
613 // Only extension 2 should have become disabled. | 712 // Only extension 2 should have become disabled. |
614 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 713 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
615 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); | 714 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); |
616 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 715 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
617 // No extension should have been acknowledged (it got disabled). | 716 // No extension should have been acknowledged (it got disabled). |
618 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); | 717 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); |
619 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); | 718 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); |
620 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); | 719 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); |
621 | 720 |
622 // Clean up after ourselves. | 721 // Clean up after ourselves. |
623 service_->UninstallExtension(kId1, false, NULL); | 722 service_->UninstallExtension(kId1, false, NULL); |
624 service_->UninstallExtension(kId2, false, NULL); | 723 service_->UninstallExtension(kId2, false, NULL); |
625 service_->UninstallExtension(kId3, false, NULL); | 724 service_->UninstallExtension(kId3, false, NULL); |
626 } | 725 } |
627 } | 726 } |
628 | 727 |
629 // The feature this is meant to test is only implemented on Windows. | 728 // The feature this is meant to test is only implemented on Windows. |
630 #if defined(OS_WIN) | 729 #if defined(OS_WIN) |
631 #define MAYBE_NtpOverriddenControllerTest NtpOverriddenControllerTest | 730 #define MAYBE_NtpOverriddenControllerTest NtpOverriddenControllerTest |
632 #else | 731 #else |
633 #define MAYBE_NtpOverriddenControllerTest DISABLED_NtpOverriddenControllerTest | 732 #define MAYBE_NtpOverriddenControllerTest DISABLED_NtpOverriddenControllerTest |
634 #endif | 733 #endif |
635 | 734 |
636 TEST_F(ExtensionMessageBubbleTest, MAYBE_NtpOverriddenControllerTest) { | 735 TEST_F(ExtensionMessageBubbleTest, MAYBE_NtpOverriddenControllerTest) { |
637 Init(); | 736 Init(); |
638 extensions::ExtensionPrefs* prefs = | 737 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
639 extensions::ExtensionPrefs::Get(profile()); | |
640 // Load two extensions overriding new tab page and one overriding something | 738 // Load two extensions overriding new tab page and one overriding something |
641 // unrelated (to check for interference). Extension 2 should still win | 739 // unrelated (to check for interference). Extension 2 should still win |
642 // on the new tab page setting. | 740 // on the new tab page setting. |
643 LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED); | 741 ASSERT_TRUE(LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED)); |
644 LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED); | 742 ASSERT_TRUE(LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED)); |
645 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED); | 743 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); |
646 | 744 |
647 scoped_ptr<TestNtpOverriddenBubbleController> controller( | 745 scoped_ptr<TestNtpOverriddenBubbleController> controller( |
648 new TestNtpOverriddenBubbleController(profile())); | 746 new TestNtpOverriddenBubbleController(profile())); |
649 | 747 |
650 // The list will contain one enabled unpacked extension (ext 2). | 748 // The list will contain one enabled unpacked extension (ext 2). |
651 EXPECT_TRUE(controller->ShouldShow(kId2)); | 749 EXPECT_TRUE(controller->ShouldShow(kId2)); |
652 std::vector<base::string16> override_extensions = | 750 std::vector<base::string16> override_extensions = |
653 controller->GetExtensionList(); | 751 controller->GetExtensionList(); |
654 ASSERT_EQ(1U, override_extensions.size()); | 752 ASSERT_EQ(1U, override_extensions.size()); |
655 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == | 753 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == |
656 override_extensions[0].c_str()); | 754 override_extensions[0].c_str()); |
657 EXPECT_EQ(0U, controller->link_click_count()); | 755 EXPECT_EQ(0U, controller->link_click_count()); |
658 EXPECT_EQ(0U, controller->dismiss_click_count()); | 756 EXPECT_EQ(0U, controller->dismiss_click_count()); |
659 EXPECT_EQ(0U, controller->action_click_count()); | 757 EXPECT_EQ(0U, controller->action_click_count()); |
660 | 758 |
661 // Simulate showing the bubble and dismissing it. | 759 // Simulate showing the bubble and dismissing it. |
662 FakeExtensionMessageBubble bubble; | 760 FakeExtensionMessageBubble bubble; |
663 bubble.set_action_on_show( | 761 bubble.set_action_on_show( |
664 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | 762 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
665 EXPECT_TRUE(controller->ShouldShow(kId2)); | 763 EXPECT_TRUE(controller->ShouldShow(kId2)); |
666 controller->Show(&bubble); | 764 controller->Show(&bubble); |
667 EXPECT_EQ(0U, controller->link_click_count()); | 765 EXPECT_EQ(0U, controller->link_click_count()); |
668 EXPECT_EQ(0U, controller->action_click_count()); | 766 EXPECT_EQ(0U, controller->action_click_count()); |
669 EXPECT_EQ(1U, controller->dismiss_click_count()); | 767 EXPECT_EQ(1U, controller->dismiss_click_count()); |
670 // No extension should have become disabled. | 768 // No extension should have become disabled. |
671 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 769 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
672 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 770 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
673 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 771 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
| 772 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
674 // Only extension 2 should have been acknowledged. | 773 // Only extension 2 should have been acknowledged. |
675 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); | 774 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); |
676 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); | 775 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); |
677 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); | 776 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); |
678 // Clean up after ourselves. | 777 // Clean up after ourselves. |
679 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); | 778 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); |
680 | 779 |
681 // Simulate clicking the learn more link to dismiss it. | 780 // Simulate clicking the learn more link to dismiss it. |
682 bubble.set_action_on_show( | 781 bubble.set_action_on_show( |
683 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | 782 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
684 controller.reset(new TestNtpOverriddenBubbleController(profile())); | 783 controller.reset(new TestNtpOverriddenBubbleController(profile())); |
685 EXPECT_TRUE(controller->ShouldShow(kId2)); | 784 EXPECT_TRUE(controller->ShouldShow(kId2)); |
686 controller->Show(&bubble); | 785 controller->Show(&bubble); |
687 EXPECT_EQ(1U, controller->link_click_count()); | 786 EXPECT_EQ(1U, controller->link_click_count()); |
688 EXPECT_EQ(0U, controller->action_click_count()); | 787 EXPECT_EQ(0U, controller->action_click_count()); |
689 EXPECT_EQ(0U, controller->dismiss_click_count()); | 788 EXPECT_EQ(0U, controller->dismiss_click_count()); |
690 // No extension should have become disabled. | 789 // No extension should have become disabled. |
691 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 790 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
692 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | 791 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
693 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 792 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
694 // Only extension 2 should have been acknowledged. | 793 // Only extension 2 should have been acknowledged. |
695 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); | 794 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); |
696 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); | 795 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); |
697 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); | 796 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); |
698 // Clean up after ourselves. | 797 // Clean up after ourselves. |
699 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); | 798 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); |
700 | 799 |
701 // Do it again, but now opt to disable the extension. | 800 // Do it again, but now opt to disable the extension. |
702 bubble.set_action_on_show( | 801 bubble.set_action_on_show( |
703 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | 802 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
704 controller.reset(new TestNtpOverriddenBubbleController(profile())); | 803 controller.reset(new TestNtpOverriddenBubbleController(profile())); |
705 EXPECT_TRUE(controller->ShouldShow(kId2)); | 804 EXPECT_TRUE(controller->ShouldShow(kId2)); |
706 override_extensions = controller->GetExtensionList(); | 805 override_extensions = controller->GetExtensionList(); |
707 EXPECT_EQ(1U, override_extensions.size()); | 806 EXPECT_EQ(1U, override_extensions.size()); |
708 controller->Show(&bubble); // Simulate showing the bubble. | 807 controller->Show(&bubble); // Simulate showing the bubble. |
709 EXPECT_EQ(0U, controller->link_click_count()); | 808 EXPECT_EQ(0U, controller->link_click_count()); |
710 EXPECT_EQ(1U, controller->action_click_count()); | 809 EXPECT_EQ(1U, controller->action_click_count()); |
711 EXPECT_EQ(0U, controller->dismiss_click_count()); | 810 EXPECT_EQ(0U, controller->dismiss_click_count()); |
712 // Only extension 2 should have become disabled. | 811 // Only extension 2 should have become disabled. |
713 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | 812 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
714 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); | 813 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); |
715 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | 814 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
716 // No extension should have been acknowledged (it got disabled). | 815 // No extension should have been acknowledged (it got disabled). |
717 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); | 816 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); |
718 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); | 817 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); |
719 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); | 818 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); |
720 | 819 |
721 // Clean up after ourselves. | 820 // Clean up after ourselves. |
722 service_->UninstallExtension(kId1, false, NULL); | 821 service_->UninstallExtension(kId1, false, NULL); |
723 service_->UninstallExtension(kId2, false, NULL); | 822 service_->UninstallExtension(kId2, false, NULL); |
724 service_->UninstallExtension(kId3, false, NULL); | 823 service_->UninstallExtension(kId3, false, NULL); |
725 } | 824 } |
726 | 825 |
| 826 void SetInstallTime(const std::string& extension_id, |
| 827 const base::Time& time, |
| 828 ExtensionPrefs* prefs) { |
| 829 std::string time_str = base::Int64ToString(time.ToInternalValue()); |
| 830 prefs->UpdateExtensionPref(extension_id, |
| 831 "install_time", |
| 832 new base::StringValue(time_str)); |
| 833 } |
| 834 |
| 835 // The feature this is meant to test is only implemented on Windows. |
| 836 #if defined(OS_WIN) |
| 837 #define MAYBE_ProxyOverriddenControllerTest ProxyOverriddenControllerTest |
| 838 #else |
| 839 #define MAYBE_ProxyOverriddenControllerTest DISABLED_ProxyOverriddenControllerTe
st |
| 840 #endif |
| 841 |
| 842 TEST_F(ExtensionMessageBubbleTest, MAYBE_ProxyOverriddenControllerTest) { |
| 843 Init(); |
| 844 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 845 // Load two extensions overriding proxy and one overriding something |
| 846 // unrelated (to check for interference). Extension 2 should still win |
| 847 // on the proxy setting. |
| 848 ASSERT_TRUE(LoadExtensionOverridingProxy("1", kId1, Manifest::UNPACKED)); |
| 849 ASSERT_TRUE(LoadExtensionOverridingProxy("2", kId2, Manifest::UNPACKED)); |
| 850 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); |
| 851 |
| 852 // The bubble will not show if the extension was installed in the last 7 days |
| 853 // so we artificially set the install time to simulate an old install during |
| 854 // testing. |
| 855 base::Time old_enough = base::Time::Now() - base::TimeDelta::FromDays(8); |
| 856 SetInstallTime(kId1, old_enough, prefs); |
| 857 SetInstallTime(kId2, base::Time::Now(), prefs); |
| 858 SetInstallTime(kId3, old_enough, prefs); |
| 859 |
| 860 scoped_ptr<TestProxyOverriddenBubbleController> controller( |
| 861 new TestProxyOverriddenBubbleController(profile())); |
| 862 |
| 863 // The second extension is too new to warn about. |
| 864 EXPECT_FALSE(controller->ShouldShow(kId1)); |
| 865 EXPECT_FALSE(controller->ShouldShow(kId2)); |
| 866 // Lets make it old enough. |
| 867 SetInstallTime(kId2, old_enough, prefs); |
| 868 |
| 869 // The list will contain one enabled unpacked extension (ext 2). |
| 870 EXPECT_TRUE(controller->ShouldShow(kId2)); |
| 871 EXPECT_FALSE(controller->ShouldShow(kId3)); |
| 872 std::vector<base::string16> override_extensions = |
| 873 controller->GetExtensionList(); |
| 874 ASSERT_EQ(1U, override_extensions.size()); |
| 875 EXPECT_EQ(base::ASCIIToUTF16("Extension 2"), override_extensions[0]); |
| 876 EXPECT_EQ(0U, controller->link_click_count()); |
| 877 EXPECT_EQ(0U, controller->dismiss_click_count()); |
| 878 EXPECT_EQ(0U, controller->action_click_count()); |
| 879 |
| 880 // Simulate showing the bubble and dismissing it. |
| 881 FakeExtensionMessageBubble bubble; |
| 882 bubble.set_action_on_show( |
| 883 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); |
| 884 controller->Show(&bubble); |
| 885 EXPECT_EQ(0U, controller->link_click_count()); |
| 886 EXPECT_EQ(0U, controller->action_click_count()); |
| 887 EXPECT_EQ(1U, controller->dismiss_click_count()); |
| 888 // No extension should have become disabled. |
| 889 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 890 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
| 891 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
| 892 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
| 893 // Only extension 2 should have been acknowledged. |
| 894 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); |
| 895 EXPECT_TRUE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); |
| 896 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); |
| 897 // Clean up after ourselves. |
| 898 prefs->SetProxyOverriddenBubbleBeenAcknowledged(kId2, false); |
| 899 |
| 900 // Simulate clicking the learn more link to dismiss it. |
| 901 bubble.set_action_on_show( |
| 902 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); |
| 903 controller.reset(new TestProxyOverriddenBubbleController(profile())); |
| 904 EXPECT_TRUE(controller->ShouldShow(kId2)); |
| 905 controller->Show(&bubble); |
| 906 EXPECT_EQ(1U, controller->link_click_count()); |
| 907 EXPECT_EQ(0U, controller->action_click_count()); |
| 908 EXPECT_EQ(0U, controller->dismiss_click_count()); |
| 909 // No extension should have become disabled. |
| 910 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
| 911 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); |
| 912 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
| 913 // Only extension 2 should have been acknowledged. |
| 914 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); |
| 915 EXPECT_TRUE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); |
| 916 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); |
| 917 // Clean up after ourselves. |
| 918 prefs->SetProxyOverriddenBubbleBeenAcknowledged(kId2, false); |
| 919 |
| 920 // Do it again, but now opt to disable the extension. |
| 921 bubble.set_action_on_show( |
| 922 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); |
| 923 controller.reset(new TestProxyOverriddenBubbleController(profile())); |
| 924 EXPECT_TRUE(controller->ShouldShow(kId2)); |
| 925 override_extensions = controller->GetExtensionList(); |
| 926 EXPECT_EQ(1U, override_extensions.size()); |
| 927 controller->Show(&bubble); // Simulate showing the bubble. |
| 928 EXPECT_EQ(0U, controller->link_click_count()); |
| 929 EXPECT_EQ(1U, controller->action_click_count()); |
| 930 EXPECT_EQ(0U, controller->dismiss_click_count()); |
| 931 // Only extension 2 should have become disabled. |
| 932 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); |
| 933 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); |
| 934 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); |
| 935 // No extension should have been acknowledged (it got disabled). |
| 936 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); |
| 937 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); |
| 938 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); |
| 939 |
| 940 // Clean up after ourselves. |
| 941 service_->UninstallExtension(kId1, false, NULL); |
| 942 service_->UninstallExtension(kId2, false, NULL); |
| 943 service_->UninstallExtension(kId3, false, NULL); |
| 944 } |
| 945 |
727 } // namespace extensions | 946 } // namespace extensions |
OLD | NEW |