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

Side by Side Diff: trunk/src/chrome/browser/extensions/extension_message_bubble_controller_unittest.cc

Issue 312403003: Revert 275229 "Add an extension override bubble and warning box ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
7 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" 8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
11 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
12 #include "chrome/browser/extensions/extension_message_bubble.h" 10 #include "chrome/browser/extensions/extension_message_bubble.h"
13 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h" 12 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h"
15 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h"
16 #include "chrome/browser/extensions/settings_api_bubble_controller.h" 13 #include "chrome/browser/extensions/settings_api_bubble_controller.h"
17 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" 14 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h"
18 #include "chrome/browser/extensions/test_extension_system.h" 15 #include "chrome/browser/extensions/test_extension_system.h"
19 #include "chrome/common/chrome_version_info.h" 16 #include "chrome/common/chrome_version_info.h"
20 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 18 #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"
25 #include "extensions/browser/extension_prefs.h" 19 #include "extensions/browser/extension_prefs.h"
26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
28 #include "extensions/common/extension_builder.h" 21 #include "extensions/common/extension_builder.h"
29 #include "extensions/common/feature_switch.h" 22 #include "extensions/common/feature_switch.h"
30 #include "extensions/common/value_builder.h"
31 23
32 namespace { 24 namespace {
33 25
34 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; 26 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk";
35 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; 27 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl";
36 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; 28 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek";
37 29
38 } // namespace 30 } // namespace
39 31
40 namespace extensions { 32 namespace extensions {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ++dismiss_button_callback_count_; 152 ++dismiss_button_callback_count_;
161 NtpOverriddenBubbleController::OnBubbleDismiss(); 153 NtpOverriddenBubbleController::OnBubbleDismiss();
162 } 154 }
163 155
164 virtual void OnLinkClicked() OVERRIDE { 156 virtual void OnLinkClicked() OVERRIDE {
165 ++link_click_callback_count_; 157 ++link_click_callback_count_;
166 NtpOverriddenBubbleController::OnLinkClicked(); 158 NtpOverriddenBubbleController::OnLinkClicked();
167 } 159 }
168 }; 160 };
169 161
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
195 // A fake bubble used for testing the controller. Takes an action that specifies 162 // A fake bubble used for testing the controller. Takes an action that specifies
196 // what should happen when the bubble is "shown" (the bubble is actually not 163 // what should happen when the bubble is "shown" (the bubble is actually not
197 // shown, the corresponding action is taken immediately). 164 // shown, the corresponding action is taken immediately).
198 class FakeExtensionMessageBubble : public ExtensionMessageBubble { 165 class FakeExtensionMessageBubble : public ExtensionMessageBubble {
199 public: 166 public:
200 enum ExtensionBubbleAction { 167 enum ExtensionBubbleAction {
201 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, 168 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0,
202 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, 169 BUBBLE_ACTION_CLICK_DISMISS_BUTTON,
203 BUBBLE_ACTION_CLICK_LINK, 170 BUBBLE_ACTION_CLICK_LINK,
204 }; 171 };
(...skipping 30 matching lines...) Expand all
235 202
236 base::Closure action_callback_; 203 base::Closure action_callback_;
237 base::Closure dismiss_callback_; 204 base::Closure dismiss_callback_;
238 base::Closure link_callback_; 205 base::Closure link_callback_;
239 }; 206 };
240 207
241 class ExtensionMessageBubbleTest : public testing::Test { 208 class ExtensionMessageBubbleTest : public testing::Test {
242 public: 209 public:
243 ExtensionMessageBubbleTest() {} 210 ExtensionMessageBubbleTest() {}
244 211
245 testing::AssertionResult LoadGenericExtension(const std::string& index, 212 void LoadGenericExtension(const std::string& index,
246 const std::string& id, 213 const std::string& id,
247 Manifest::Location location) { 214 Manifest::Location location) {
248 ExtensionBuilder builder; 215 extensions::ExtensionBuilder builder;
249 builder.SetManifest(DictionaryBuilder() 216 builder.SetManifest(extensions::DictionaryBuilder()
250 .Set("name", std::string("Extension " + index)) 217 .Set("name", std::string("Extension " + index))
251 .Set("version", "1.0") 218 .Set("version", "1.0")
252 .Set("manifest_version", 2)); 219 .Set("manifest_version", 2));
253 builder.SetLocation(location); 220 builder.SetLocation(location);
254 builder.SetID(id); 221 builder.SetID(id);
255 service_->AddExtension(builder.Build().get()); 222 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;
260 } 223 }
261 224
262 testing::AssertionResult LoadExtensionWithAction( 225 void LoadExtensionWithAction(const std::string& index,
263 const std::string& index, 226 const std::string& id,
264 const std::string& id, 227 Manifest::Location location) {
265 Manifest::Location location) { 228 extensions::ExtensionBuilder builder;
266 ExtensionBuilder builder; 229 builder.SetManifest(extensions::DictionaryBuilder()
267 builder.SetManifest(DictionaryBuilder()
268 .Set("name", std::string("Extension " + index)) 230 .Set("name", std::string("Extension " + index))
269 .Set("version", "1.0") 231 .Set("version", "1.0")
270 .Set("manifest_version", 2) 232 .Set("manifest_version", 2)
271 .Set("browser_action", 233 .Set("browser_action",
272 DictionaryBuilder().Set( 234 extensions::DictionaryBuilder().Set(
273 "default_title", "Default title"))); 235 "default_title", "Default title")));
274 builder.SetLocation(location); 236 builder.SetLocation(location);
275 builder.SetID(id); 237 builder.SetID(id);
276 service_->AddExtension(builder.Build().get()); 238 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;
281 } 239 }
282 240
283 testing::AssertionResult LoadExtensionOverridingHome( 241 void LoadExtensionOverridingHome(const std::string& index,
284 const std::string& index, 242 const std::string& id,
285 const std::string& id, 243 Manifest::Location location) {
286 Manifest::Location location) { 244 extensions::ExtensionBuilder builder;
287 ExtensionBuilder builder; 245 builder.SetManifest(extensions::DictionaryBuilder()
288 builder.SetManifest(DictionaryBuilder()
289 .Set("name", std::string("Extension " + index)) 246 .Set("name", std::string("Extension " + index))
290 .Set("version", "1.0") 247 .Set("version", "1.0")
291 .Set("manifest_version", 2) 248 .Set("manifest_version", 2)
292 .Set("chrome_settings_overrides", 249 .Set("chrome_settings_overrides",
293 DictionaryBuilder().Set( 250 extensions::DictionaryBuilder().Set(
294 "homepage", "http://www.google.com"))); 251 "homepage", "http://www.google.com")));
295 builder.SetLocation(location); 252 builder.SetLocation(location);
296 builder.SetID(id); 253 builder.SetID(id);
297 service_->AddExtension(builder.Build().get()); 254 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;
302 } 255 }
303 256
304 testing::AssertionResult LoadExtensionOverridingStart( 257 void LoadExtensionOverridingStart(const std::string& index,
305 const std::string& index, 258 const std::string& id,
306 const std::string& id, 259 Manifest::Location location) {
307 Manifest::Location location) { 260 extensions::ExtensionBuilder builder;
308 ExtensionBuilder builder; 261 builder.SetManifest(extensions::DictionaryBuilder()
309 builder.SetManifest(DictionaryBuilder()
310 .Set("name", std::string("Extension " + index)) 262 .Set("name", std::string("Extension " + index))
311 .Set("version", "1.0") 263 .Set("version", "1.0")
312 .Set("manifest_version", 2) 264 .Set("manifest_version", 2)
313 .Set("chrome_settings_overrides", 265 .Set("chrome_settings_overrides",
314 DictionaryBuilder().Set( 266 extensions::DictionaryBuilder().Set(
315 "startup_pages", 267 "startup_pages",
316 ListBuilder().Append( 268 extensions::ListBuilder().Append(
317 "http://www.google.com")))); 269 "http://www.google.com"))));
318 builder.SetLocation(location); 270 builder.SetLocation(location);
319 builder.SetID(id); 271 builder.SetID(id);
320 service_->AddExtension(builder.Build().get()); 272 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;
325 } 273 }
326 274
327 testing::AssertionResult LoadExtensionOverridingNtp( 275 void LoadExtensionOverridingNtp(const std::string& index,
328 const std::string& index, 276 const std::string& id,
329 const std::string& id, 277 Manifest::Location location) {
330 Manifest::Location location) { 278 extensions::ExtensionBuilder builder;
331 ExtensionBuilder builder; 279 builder.SetManifest(extensions::DictionaryBuilder()
332 builder.SetManifest(DictionaryBuilder()
333 .Set("name", std::string("Extension " + index)) 280 .Set("name", std::string("Extension " + index))
334 .Set("version", "1.0") 281 .Set("version", "1.0")
335 .Set("manifest_version", 2) 282 .Set("manifest_version", 2)
336 .Set("chrome_url_overrides", 283 .Set("chrome_url_overrides",
337 DictionaryBuilder().Set( 284 extensions::DictionaryBuilder().Set(
338 "newtab", "Default.html"))); 285 "newtab", "Default.html")));
339 286
340 builder.SetLocation(location); 287 builder.SetLocation(location);
341 builder.SetID(id); 288 builder.SetID(id);
342 service_->AddExtension(builder.Build().get()); 289 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;
385 } 290 }
386 291
387 void Init() { 292 void Init() {
388 // The two lines of magical incantation required to get the extension 293 // The two lines of magical incantation required to get the extension
389 // service to work inside a unit test and access the extension prefs. 294 // service to work inside a unit test and access the extension prefs.
390 thread_bundle_.reset(new content::TestBrowserThreadBundle); 295 thread_bundle_.reset(new content::TestBrowserThreadBundle);
391 profile_.reset(new TestingProfile); 296 profile_.reset(new TestingProfile);
392 static_cast<TestExtensionSystem*>( 297 static_cast<TestExtensionSystem*>(
393 ExtensionSystem::Get(profile()))->CreateExtensionService( 298 ExtensionSystem::Get(profile()))->CreateExtensionService(
394 CommandLine::ForCurrentProcess(), 299 CommandLine::ForCurrentProcess(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 #if defined(OS_WIN) 341 #if defined(OS_WIN)
437 #define MAYBE_WipeoutControllerTest WipeoutControllerTest 342 #define MAYBE_WipeoutControllerTest WipeoutControllerTest
438 #else 343 #else
439 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest 344 #define MAYBE_WipeoutControllerTest DISABLED_WipeoutControllerTest
440 #endif 345 #endif
441 346
442 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) { 347 TEST_F(ExtensionMessageBubbleTest, MAYBE_WipeoutControllerTest) {
443 Init(); 348 Init();
444 // Add three extensions, and control two of them in this test (extension 1 349 // Add three extensions, and control two of them in this test (extension 1
445 // and 2). 350 // and 2).
446 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); 351 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE);
447 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); 352 LoadGenericExtension("2", kId2, Manifest::UNPACKED);
448 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); 353 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY);
449 354
450 scoped_ptr<TestSuspiciousExtensionBubbleController> controller( 355 scoped_ptr<TestSuspiciousExtensionBubbleController> controller(
451 new TestSuspiciousExtensionBubbleController(profile())); 356 new TestSuspiciousExtensionBubbleController(profile()));
452 FakeExtensionMessageBubble bubble; 357 FakeExtensionMessageBubble bubble;
453 bubble.set_action_on_show( 358 bubble.set_action_on_show(
454 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); 359 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON);
455 360
456 // Validate that we don't have a suppress value for the extensions. 361 // Validate that we don't have a suppress value for the extensions.
457 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); 362 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
458 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1)); 363 EXPECT_FALSE(prefs->HasWipeoutBeenAcknowledged(kId1));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest 418 #define MAYBE_DevModeControllerTest DISABLED_DevModeControllerTest
514 #endif 419 #endif
515 420
516 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) { 421 TEST_F(ExtensionMessageBubbleTest, MAYBE_DevModeControllerTest) {
517 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( 422 FeatureSwitch::ScopedOverride force_dev_mode_highlighting(
518 FeatureSwitch::force_dev_mode_highlighting(), true); 423 FeatureSwitch::force_dev_mode_highlighting(), true);
519 Init(); 424 Init();
520 // Add three extensions, and control two of them in this test (extension 1 425 // Add three extensions, and control two of them in this test (extension 1
521 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it 426 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it
522 // counts as a DevMode extension. 427 // counts as a DevMode extension.
523 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); 428 LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE);
524 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); 429 LoadGenericExtension("2", kId2, Manifest::UNPACKED);
525 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); 430 LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY);
526 431
527 scoped_ptr<TestDevModeBubbleController> controller( 432 scoped_ptr<TestDevModeBubbleController> controller(
528 new TestDevModeBubbleController(profile())); 433 new TestDevModeBubbleController(profile()));
529 434
530 // The list will contain one enabled unpacked extension. 435 // The list will contain one enabled unpacked extension.
531 EXPECT_TRUE(controller->ShouldShow()); 436 EXPECT_TRUE(controller->ShouldShow());
532 std::vector<base::string16> dev_mode_extensions = 437 std::vector<base::string16> dev_mode_extensions =
533 controller->GetExtensionList(); 438 controller->GetExtensionList();
534 ASSERT_EQ(2U, dev_mode_extensions.size()); 439 ASSERT_EQ(2U, dev_mode_extensions.size());
535 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); 440 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]);
536 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); 441 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]);
537 EXPECT_EQ(0U, controller->link_click_count()); 442 EXPECT_EQ(0U, controller->link_click_count());
538 EXPECT_EQ(0U, controller->dismiss_click_count()); 443 EXPECT_EQ(0U, controller->dismiss_click_count());
539 EXPECT_EQ(0U, controller->action_click_count()); 444 EXPECT_EQ(0U, controller->action_click_count());
540 445
541 // Simulate showing the bubble. 446 // Simulate showing the bubble.
542 FakeExtensionMessageBubble bubble; 447 FakeExtensionMessageBubble bubble;
543 bubble.set_action_on_show( 448 bubble.set_action_on_show(
544 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); 449 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON);
545 controller->Show(&bubble); 450 controller->Show(&bubble);
546 EXPECT_EQ(0U, controller->link_click_count()); 451 EXPECT_EQ(0U, controller->link_click_count());
547 EXPECT_EQ(0U, controller->action_click_count()); 452 EXPECT_EQ(0U, controller->action_click_count());
548 EXPECT_EQ(1U, controller->dismiss_click_count()); 453 EXPECT_EQ(1U, controller->dismiss_click_count());
549 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 454 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
550 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 455 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
551 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL);
552 456
553 // Do it again, but now press different button (Disable). 457 // Do it again, but now press different button (Disable).
554 bubble.set_action_on_show( 458 bubble.set_action_on_show(
555 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); 459 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON);
556 controller.reset(new TestDevModeBubbleController( 460 controller.reset(new TestDevModeBubbleController(
557 profile())); 461 profile()));
558 DevModeBubbleController::ClearProfileListForTesting(); 462 DevModeBubbleController::ClearProfileListForTesting();
559 EXPECT_TRUE(controller->ShouldShow()); 463 EXPECT_TRUE(controller->ShouldShow());
560 dev_mode_extensions = controller->GetExtensionList(); 464 dev_mode_extensions = controller->GetExtensionList();
561 EXPECT_EQ(2U, dev_mode_extensions.size()); 465 EXPECT_EQ(2U, dev_mode_extensions.size());
562 controller->Show(&bubble); // Simulate showing the bubble. 466 controller->Show(&bubble); // Simulate showing the bubble.
563 EXPECT_EQ(0U, controller->link_click_count()); 467 EXPECT_EQ(0U, controller->link_click_count());
564 EXPECT_EQ(1U, controller->action_click_count()); 468 EXPECT_EQ(1U, controller->action_click_count());
565 EXPECT_EQ(0U, controller->dismiss_click_count()); 469 EXPECT_EQ(0U, controller->dismiss_click_count());
566 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId1) != NULL); 470 EXPECT_TRUE(service_->GetExtensionById(kId1, false) == NULL);
567 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); 471 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL);
568 472
569 // Re-enable the extensions (disabled by the action button above). 473 // Re-enable the extensions (disabled by the action button above).
570 service_->EnableExtension(kId1); 474 service_->EnableExtension(kId1);
571 service_->EnableExtension(kId2); 475 service_->EnableExtension(kId2);
572 476
573 // Show the dialog a third time, but now press the learn more link. 477 // Show the dialog a third time, but now press the learn more link.
574 bubble.set_action_on_show( 478 bubble.set_action_on_show(
575 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); 479 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK);
576 controller.reset(new TestDevModeBubbleController( 480 controller.reset(new TestDevModeBubbleController(
577 profile())); 481 profile()));
578 DevModeBubbleController::ClearProfileListForTesting(); 482 DevModeBubbleController::ClearProfileListForTesting();
579 EXPECT_TRUE(controller->ShouldShow()); 483 EXPECT_TRUE(controller->ShouldShow());
580 dev_mode_extensions = controller->GetExtensionList(); 484 dev_mode_extensions = controller->GetExtensionList();
581 EXPECT_EQ(2U, dev_mode_extensions.size()); 485 EXPECT_EQ(2U, dev_mode_extensions.size());
582 controller->Show(&bubble); // Simulate showing the bubble. 486 controller->Show(&bubble); // Simulate showing the bubble.
583 EXPECT_EQ(1U, controller->link_click_count()); 487 EXPECT_EQ(1U, controller->link_click_count());
584 EXPECT_EQ(0U, controller->action_click_count()); 488 EXPECT_EQ(0U, controller->action_click_count());
585 EXPECT_EQ(0U, controller->dismiss_click_count()); 489 EXPECT_EQ(0U, controller->dismiss_click_count());
586 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 490 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
587 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); 491 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
588 492
589 // Now disable the unpacked extension. 493 // Now disable the unpacked extension.
590 service_->DisableExtension(kId1, Extension::DISABLE_USER_ACTION); 494 service_->DisableExtension(kId1, Extension::DISABLE_USER_ACTION);
591 service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION); 495 service_->DisableExtension(kId2, Extension::DISABLE_USER_ACTION);
592 496
593 controller.reset(new TestDevModeBubbleController( 497 controller.reset(new TestDevModeBubbleController(
594 profile())); 498 profile()));
595 DevModeBubbleController::ClearProfileListForTesting(); 499 DevModeBubbleController::ClearProfileListForTesting();
596 EXPECT_FALSE(controller->ShouldShow()); 500 EXPECT_FALSE(controller->ShouldShow());
597 dev_mode_extensions = controller->GetExtensionList(); 501 dev_mode_extensions = controller->GetExtensionList();
598 EXPECT_EQ(0U, dev_mode_extensions.size()); 502 EXPECT_EQ(0U, dev_mode_extensions.size());
599 } 503 }
600 504
601 // The feature this is meant to test is only implemented on Windows. 505 // The feature this is meant to test is only implemented on Windows.
602 #if defined(OS_WIN) 506 #if defined(OS_WIN)
603 #define MAYBE_SettingsApiControllerTest SettingsApiControllerTest 507 #define MAYBE_SettingsApiControllerTest SettingsApiControllerTest
604 #else 508 #else
605 #define MAYBE_SettingsApiControllerTest DISABLED_SettingsApiControllerTest 509 #define MAYBE_SettingsApiControllerTest DISABLED_SettingsApiControllerTest
606 #endif 510 #endif
607 511
608 TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) { 512 TEST_F(ExtensionMessageBubbleTest, MAYBE_SettingsApiControllerTest) {
609 Init(); 513 Init();
610 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); 514 extensions::ExtensionPrefs* prefs =
515 extensions::ExtensionPrefs::Get(profile());
611 516
612 for (int i = 0; i < 3; ++i) { 517 for (int i = 0; i < 3; ++i) {
613 switch (static_cast<SettingsApiOverrideType>(i)) { 518 switch (static_cast<SettingsApiOverrideType>(i)) {
614 case BUBBLE_TYPE_HOME_PAGE: 519 case BUBBLE_TYPE_HOME_PAGE:
615 // Load two extensions overriding home page and one overriding something 520 // Load two extensions overriding home page and one overriding something
616 // unrelated (to check for interference). Extension 2 should still win 521 // unrelated (to check for interference). Extension 2 should still win
617 // on the home page setting. 522 // on the home page setting.
618 ASSERT_TRUE(LoadExtensionOverridingHome("1", kId1, Manifest::UNPACKED)); 523 LoadExtensionOverridingHome("1", kId1, Manifest::UNPACKED);
619 ASSERT_TRUE(LoadExtensionOverridingHome("2", kId2, Manifest::UNPACKED)); 524 LoadExtensionOverridingHome("2", kId2, Manifest::UNPACKED);
620 ASSERT_TRUE( 525 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED);
621 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED));
622 break; 526 break;
623 case BUBBLE_TYPE_SEARCH_ENGINE: 527 case BUBBLE_TYPE_SEARCH_ENGINE:
624 // We deliberately skip testing the search engine since it relies on 528 // We deliberately skip testing the search engine since it relies on
625 // TemplateURLServiceFactory that isn't available while unit testing. 529 // TemplateURLServiceFactory that isn't available while unit testing.
626 // This test is only simulating the bubble interaction with the user and 530 // This test is only simulating the bubble interaction with the user and
627 // that is more or less the same for the search engine as it is for the 531 // that is more or less the same for the search engine as it is for the
628 // others. 532 // others.
629 continue; 533 continue;
630 case BUBBLE_TYPE_STARTUP_PAGES: 534 case BUBBLE_TYPE_STARTUP_PAGES:
631 // Load two extensions overriding start page and one overriding 535 // Load two extensions overriding start page and one overriding
632 // something unrelated (to check for interference). Extension 2 should 536 // something unrelated (to check for interference). Extension 2 should
633 // still win on the startup page setting. 537 // still win on the startup page setting.
634 ASSERT_TRUE( 538 LoadExtensionOverridingStart("1", kId1, Manifest::UNPACKED);
635 LoadExtensionOverridingStart("1", kId1, Manifest::UNPACKED)); 539 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED);
636 ASSERT_TRUE( 540 LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED);
637 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED));
638 ASSERT_TRUE(LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED));
639 break; 541 break;
640 default: 542 default:
641 NOTREACHED(); 543 NOTREACHED();
642 break; 544 break;
643 } 545 }
644 546
645 scoped_ptr<TestSettingsApiBubbleController> controller( 547 scoped_ptr<TestSettingsApiBubbleController> controller(
646 new TestSettingsApiBubbleController( 548 new TestSettingsApiBubbleController(
647 profile(), static_cast<SettingsApiOverrideType>(i))); 549 profile(), static_cast<SettingsApiOverrideType>(i)));
648 550
(...skipping 10 matching lines...) Expand all
659 561
660 // Simulate showing the bubble and dismissing it. 562 // Simulate showing the bubble and dismissing it.
661 FakeExtensionMessageBubble bubble; 563 FakeExtensionMessageBubble bubble;
662 bubble.set_action_on_show( 564 bubble.set_action_on_show(
663 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); 565 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON);
664 controller->Show(&bubble); 566 controller->Show(&bubble);
665 EXPECT_EQ(0U, controller->link_click_count()); 567 EXPECT_EQ(0U, controller->link_click_count());
666 EXPECT_EQ(0U, controller->action_click_count()); 568 EXPECT_EQ(0U, controller->action_click_count());
667 EXPECT_EQ(1U, controller->dismiss_click_count()); 569 EXPECT_EQ(1U, controller->dismiss_click_count());
668 // No extension should have become disabled. 570 // No extension should have become disabled.
669 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 571 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
670 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 572 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
671 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); 573 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
672 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL);
673 // Only extension 2 should have been acknowledged. 574 // Only extension 2 should have been acknowledged.
674 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); 575 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1));
675 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); 576 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2));
676 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); 577 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3));
677 // Clean up after ourselves. 578 // Clean up after ourselves.
678 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); 579 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false);
679 580
680 // Simulate clicking the learn more link to dismiss it. 581 // Simulate clicking the learn more link to dismiss it.
681 bubble.set_action_on_show( 582 bubble.set_action_on_show(
682 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); 583 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK);
683 controller.reset(new TestSettingsApiBubbleController( 584 controller.reset(new TestSettingsApiBubbleController(
684 profile(), static_cast<SettingsApiOverrideType>(i))); 585 profile(), static_cast<SettingsApiOverrideType>(i)));
685 controller->Show(&bubble); 586 controller->Show(&bubble);
686 EXPECT_EQ(1U, controller->link_click_count()); 587 EXPECT_EQ(1U, controller->link_click_count());
687 EXPECT_EQ(0U, controller->action_click_count()); 588 EXPECT_EQ(0U, controller->action_click_count());
688 EXPECT_EQ(0U, controller->dismiss_click_count()); 589 EXPECT_EQ(0U, controller->dismiss_click_count());
689 // No extension should have become disabled. 590 // No extension should have become disabled.
690 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 591 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
691 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); 592 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
692 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); 593 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
693 // Only extension 2 should have been acknowledged. 594 // Only extension 2 should have been acknowledged.
694 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); 595 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1));
695 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); 596 EXPECT_TRUE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2));
696 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); 597 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3));
697 // Clean up after ourselves. 598 // Clean up after ourselves.
698 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false); 599 prefs->SetSettingsApiBubbleBeenAcknowledged(kId2, false);
699 600
700 // Do it again, but now opt to disable the extension. 601 // Do it again, but now opt to disable the extension.
701 bubble.set_action_on_show( 602 bubble.set_action_on_show(
702 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); 603 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON);
703 controller.reset(new TestSettingsApiBubbleController( 604 controller.reset(new TestSettingsApiBubbleController(
704 profile(), static_cast<SettingsApiOverrideType>(i))); 605 profile(), static_cast<SettingsApiOverrideType>(i)));
705 EXPECT_TRUE(controller->ShouldShow(kId2)); 606 EXPECT_TRUE(controller->ShouldShow(kId2));
706 override_extensions = controller->GetExtensionList(); 607 override_extensions = controller->GetExtensionList();
707 EXPECT_EQ(1U, override_extensions.size()); 608 EXPECT_EQ(1U, override_extensions.size());
708 controller->Show(&bubble); // Simulate showing the bubble. 609 controller->Show(&bubble); // Simulate showing the bubble.
709 EXPECT_EQ(0U, controller->link_click_count()); 610 EXPECT_EQ(0U, controller->link_click_count());
710 EXPECT_EQ(1U, controller->action_click_count()); 611 EXPECT_EQ(1U, controller->action_click_count());
711 EXPECT_EQ(0U, controller->dismiss_click_count()); 612 EXPECT_EQ(0U, controller->dismiss_click_count());
712 // Only extension 2 should have become disabled. 613 // Only extension 2 should have become disabled.
713 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 614 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
714 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); 615 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL);
715 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); 616 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
716 // No extension should have been acknowledged (it got disabled). 617 // No extension should have been acknowledged (it got disabled).
717 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1)); 618 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId1));
718 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); 619 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2));
719 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); 620 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3));
720 621
721 // Clean up after ourselves. 622 // Clean up after ourselves.
722 service_->UninstallExtension(kId1, false, NULL); 623 service_->UninstallExtension(kId1, false, NULL);
723 service_->UninstallExtension(kId2, false, NULL); 624 service_->UninstallExtension(kId2, false, NULL);
724 service_->UninstallExtension(kId3, false, NULL); 625 service_->UninstallExtension(kId3, false, NULL);
725 } 626 }
726 } 627 }
727 628
728 // The feature this is meant to test is only implemented on Windows. 629 // The feature this is meant to test is only implemented on Windows.
729 #if defined(OS_WIN) 630 #if defined(OS_WIN)
730 #define MAYBE_NtpOverriddenControllerTest NtpOverriddenControllerTest 631 #define MAYBE_NtpOverriddenControllerTest NtpOverriddenControllerTest
731 #else 632 #else
732 #define MAYBE_NtpOverriddenControllerTest DISABLED_NtpOverriddenControllerTest 633 #define MAYBE_NtpOverriddenControllerTest DISABLED_NtpOverriddenControllerTest
733 #endif 634 #endif
734 635
735 TEST_F(ExtensionMessageBubbleTest, MAYBE_NtpOverriddenControllerTest) { 636 TEST_F(ExtensionMessageBubbleTest, MAYBE_NtpOverriddenControllerTest) {
736 Init(); 637 Init();
737 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); 638 extensions::ExtensionPrefs* prefs =
639 extensions::ExtensionPrefs::Get(profile());
738 // Load two extensions overriding new tab page and one overriding something 640 // Load two extensions overriding new tab page and one overriding something
739 // unrelated (to check for interference). Extension 2 should still win 641 // unrelated (to check for interference). Extension 2 should still win
740 // on the new tab page setting. 642 // on the new tab page setting.
741 ASSERT_TRUE(LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED)); 643 LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED);
742 ASSERT_TRUE(LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED)); 644 LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED);
743 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); 645 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED);
744 646
745 scoped_ptr<TestNtpOverriddenBubbleController> controller( 647 scoped_ptr<TestNtpOverriddenBubbleController> controller(
746 new TestNtpOverriddenBubbleController(profile())); 648 new TestNtpOverriddenBubbleController(profile()));
747 649
748 // The list will contain one enabled unpacked extension (ext 2). 650 // The list will contain one enabled unpacked extension (ext 2).
749 EXPECT_TRUE(controller->ShouldShow(kId2)); 651 EXPECT_TRUE(controller->ShouldShow(kId2));
750 std::vector<base::string16> override_extensions = 652 std::vector<base::string16> override_extensions =
751 controller->GetExtensionList(); 653 controller->GetExtensionList();
752 ASSERT_EQ(1U, override_extensions.size()); 654 ASSERT_EQ(1U, override_extensions.size());
753 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == 655 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") ==
754 override_extensions[0].c_str()); 656 override_extensions[0].c_str());
755 EXPECT_EQ(0U, controller->link_click_count()); 657 EXPECT_EQ(0U, controller->link_click_count());
756 EXPECT_EQ(0U, controller->dismiss_click_count()); 658 EXPECT_EQ(0U, controller->dismiss_click_count());
757 EXPECT_EQ(0U, controller->action_click_count()); 659 EXPECT_EQ(0U, controller->action_click_count());
758 660
759 // Simulate showing the bubble and dismissing it. 661 // Simulate showing the bubble and dismissing it.
760 FakeExtensionMessageBubble bubble; 662 FakeExtensionMessageBubble bubble;
761 bubble.set_action_on_show( 663 bubble.set_action_on_show(
762 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); 664 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON);
763 EXPECT_TRUE(controller->ShouldShow(kId2)); 665 EXPECT_TRUE(controller->ShouldShow(kId2));
764 controller->Show(&bubble); 666 controller->Show(&bubble);
765 EXPECT_EQ(0U, controller->link_click_count()); 667 EXPECT_EQ(0U, controller->link_click_count());
766 EXPECT_EQ(0U, controller->action_click_count()); 668 EXPECT_EQ(0U, controller->action_click_count());
767 EXPECT_EQ(1U, controller->dismiss_click_count()); 669 EXPECT_EQ(1U, controller->dismiss_click_count());
768 // No extension should have become disabled. 670 // No extension should have become disabled.
769 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 671 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
770 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 672 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
771 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); 673 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
772 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL);
773 // Only extension 2 should have been acknowledged. 674 // Only extension 2 should have been acknowledged.
774 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); 675 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1));
775 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); 676 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2));
776 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); 677 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3));
777 // Clean up after ourselves. 678 // Clean up after ourselves.
778 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); 679 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false);
779 680
780 // Simulate clicking the learn more link to dismiss it. 681 // Simulate clicking the learn more link to dismiss it.
781 bubble.set_action_on_show( 682 bubble.set_action_on_show(
782 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); 683 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK);
783 controller.reset(new TestNtpOverriddenBubbleController(profile())); 684 controller.reset(new TestNtpOverriddenBubbleController(profile()));
784 EXPECT_TRUE(controller->ShouldShow(kId2)); 685 EXPECT_TRUE(controller->ShouldShow(kId2));
785 controller->Show(&bubble); 686 controller->Show(&bubble);
786 EXPECT_EQ(1U, controller->link_click_count()); 687 EXPECT_EQ(1U, controller->link_click_count());
787 EXPECT_EQ(0U, controller->action_click_count()); 688 EXPECT_EQ(0U, controller->action_click_count());
788 EXPECT_EQ(0U, controller->dismiss_click_count()); 689 EXPECT_EQ(0U, controller->dismiss_click_count());
789 // No extension should have become disabled. 690 // No extension should have become disabled.
790 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 691 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
791 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId2) != NULL); 692 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
792 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); 693 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
793 // Only extension 2 should have been acknowledged. 694 // Only extension 2 should have been acknowledged.
794 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); 695 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1));
795 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); 696 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2));
796 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); 697 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3));
797 // Clean up after ourselves. 698 // Clean up after ourselves.
798 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false); 699 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false);
799 700
800 // Do it again, but now opt to disable the extension. 701 // Do it again, but now opt to disable the extension.
801 bubble.set_action_on_show( 702 bubble.set_action_on_show(
802 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); 703 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON);
803 controller.reset(new TestNtpOverriddenBubbleController(profile())); 704 controller.reset(new TestNtpOverriddenBubbleController(profile()));
804 EXPECT_TRUE(controller->ShouldShow(kId2)); 705 EXPECT_TRUE(controller->ShouldShow(kId2));
805 override_extensions = controller->GetExtensionList(); 706 override_extensions = controller->GetExtensionList();
806 EXPECT_EQ(1U, override_extensions.size()); 707 EXPECT_EQ(1U, override_extensions.size());
807 controller->Show(&bubble); // Simulate showing the bubble. 708 controller->Show(&bubble); // Simulate showing the bubble.
808 EXPECT_EQ(0U, controller->link_click_count()); 709 EXPECT_EQ(0U, controller->link_click_count());
809 EXPECT_EQ(1U, controller->action_click_count()); 710 EXPECT_EQ(1U, controller->action_click_count());
810 EXPECT_EQ(0U, controller->dismiss_click_count()); 711 EXPECT_EQ(0U, controller->dismiss_click_count());
811 // Only extension 2 should have become disabled. 712 // Only extension 2 should have become disabled.
812 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId1) != NULL); 713 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
813 EXPECT_TRUE(registry->disabled_extensions().GetByID(kId2) != NULL); 714 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL);
814 EXPECT_TRUE(registry->enabled_extensions().GetByID(kId3) != NULL); 715 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
815 // No extension should have been acknowledged (it got disabled). 716 // No extension should have been acknowledged (it got disabled).
816 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); 717 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1));
817 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); 718 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2));
818 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); 719 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3));
819 720
820 // Clean up after ourselves. 721 // Clean up after ourselves.
821 service_->UninstallExtension(kId1, false, NULL); 722 service_->UninstallExtension(kId1, false, NULL);
822 service_->UninstallExtension(kId2, false, NULL); 723 service_->UninstallExtension(kId2, false, NULL);
823 service_->UninstallExtension(kId3, false, NULL); 724 service_->UninstallExtension(kId3, false, NULL);
824 } 725 }
825 726
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
946 } // namespace extensions 727 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698