Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| 11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
| 12 #include "chrome/browser/extensions/test_extension_prefs.h" | 12 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 13 #include "chrome/browser/prefs/pref_change_registrar.h" | |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 16 #include "chrome/common/extensions/extension_constants.h" |
| 17 #include "chrome/common/notification_details.h" | |
| 18 #include "chrome/common/notification_source.h" | |
| 19 #include "chrome/common/notification_type.h" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 22 |
| 18 using base::Time; | 23 using base::Time; |
| 19 using base::TimeDelta; | 24 using base::TimeDelta; |
| 20 | 25 |
| 21 // Base class for tests. | 26 // Base class for tests. |
| 22 class ExtensionPrefsTest : public testing::Test { | 27 class ExtensionPrefsTest : public testing::Test { |
| 23 public: | 28 public: |
| 24 ExtensionPrefsTest() {} | 29 ExtensionPrefsTest() {} |
| 25 | 30 |
| 26 // This function will get called once, and is the right place to do operations | 31 // This function will get called once, and is the right place to do operations |
| 27 // on ExtensionPrefs that write data. | 32 // on ExtensionPrefs that write data. |
| 28 virtual void Initialize() = 0; | 33 virtual void Initialize() = 0; |
| 29 | 34 |
| 30 // This function will be called twice - once while the original ExtensionPrefs | 35 // This function will be called twice - once while the original ExtensionPrefs |
| 31 // object is still alive, and once after recreation. Thus, it tests that | 36 // object is still alive, and once after recreation. Thus, it tests that |
| 32 // things don't break after any ExtensionPrefs startup work. | 37 // things don't break after any ExtensionPrefs startup work. |
| 33 virtual void Verify() = 0; | 38 virtual void Verify() = 0; |
| 34 | 39 |
| 40 // This function is called to Register preference default values. | |
| 41 virtual void RegisterPreferences() {} | |
| 42 | |
| 35 virtual void SetUp() { | 43 virtual void SetUp() { |
| 44 RegisterPreferences(); | |
| 36 Initialize(); | 45 Initialize(); |
| 37 } | 46 } |
| 38 | 47 |
| 39 virtual void TearDown() { | 48 virtual void TearDown() { |
| 40 Verify(); | 49 Verify(); |
| 41 | 50 |
| 42 // Reset ExtensionPrefs, and re-verify. | 51 // Reset ExtensionPrefs, and re-verify. |
| 43 prefs_.RecreateExtensionPrefs(); | 52 prefs_.RecreateExtensionPrefs(); |
| 53 RegisterPreferences(); | |
| 44 Verify(); | 54 Verify(); |
| 45 } | 55 } |
| 46 | 56 |
| 47 protected: | 57 protected: |
| 48 ExtensionPrefs* prefs() { return prefs_.prefs(); } | 58 ExtensionPrefs* prefs() { return prefs_.prefs(); } |
| 49 | 59 |
| 50 TestExtensionPrefs prefs_; | 60 TestExtensionPrefs prefs_; |
| 51 | 61 |
| 52 private: | 62 private: |
| 53 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefsTest); | 63 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefsTest); |
| 54 }; | 64 }; |
| 55 | 65 |
| 66 // Mock MockObserver that allows the notifications to be tracked. | |
| 67 class MockObserver : public NotificationObserver { | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Drop this in favor of chrome/test/mock_notificatio
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
| 68 public: | |
| 69 MockObserver() {} | |
| 70 virtual ~MockObserver() {} | |
| 71 MOCK_METHOD3(Observe, void(NotificationType type, | |
| 72 const NotificationSource& source, | |
| 73 const NotificationDetails& details)); | |
| 74 }; | |
| 75 | |
| 56 // Tests the LastPingDay/SetLastPingDay functions. | 76 // Tests the LastPingDay/SetLastPingDay functions. |
| 57 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { | 77 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { |
| 58 public: | 78 public: |
| 59 ExtensionPrefsLastPingDay() | 79 ExtensionPrefsLastPingDay() |
| 60 : extension_time_(Time::Now() - TimeDelta::FromHours(4)), | 80 : extension_time_(Time::Now() - TimeDelta::FromHours(4)), |
| 61 blacklist_time_(Time::Now() - TimeDelta::FromHours(2)) {} | 81 blacklist_time_(Time::Now() - TimeDelta::FromHours(2)) {} |
| 62 | 82 |
| 63 virtual void Initialize() { | 83 virtual void Initialize() { |
| 64 extension_id_ = prefs_.AddExtensionAndReturnId("last_ping_day"); | 84 extension_id_ = prefs_.AddExtensionAndReturnId("last_ping_day"); |
| 65 EXPECT_TRUE(prefs()->LastPingDay(extension_id_).is_null()); | 85 EXPECT_TRUE(prefs()->LastPingDay(extension_id_).is_null()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); | 198 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); |
| 179 | 199 |
| 180 ExtensionList::const_iterator iter; | 200 ExtensionList::const_iterator iter; |
| 181 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { | 201 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { |
| 182 EXPECT_FALSE(prefs()->IsExtensionBlacklisted((*iter)->id())); | 202 EXPECT_FALSE(prefs()->IsExtensionBlacklisted((*iter)->id())); |
| 183 } | 203 } |
| 184 // Blacklist one installed and one not-installed extension id. | 204 // Blacklist one installed and one not-installed extension id. |
| 185 std::set<std::string> blacklisted_ids; | 205 std::set<std::string> blacklisted_ids; |
| 186 blacklisted_ids.insert(extensions_[0]->id()); | 206 blacklisted_ids.insert(extensions_[0]->id()); |
| 187 blacklisted_ids.insert(not_installed_id_); | 207 blacklisted_ids.insert(not_installed_id_); |
| 208 | |
| 209 // TODO(battre) This prints some nasty "Error parsing installation time of | |
| 210 // extension" messages because the extension preferences have incomplete | |
| 211 // dictionaries (they contain only the blacklist-property). | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Triggering error messages in unit_tests is a commo
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
| 188 prefs()->UpdateBlacklist(blacklisted_ids); | 212 prefs()->UpdateBlacklist(blacklisted_ids); |
| 189 } | 213 } |
| 190 | 214 |
| 191 virtual void Verify() { | 215 virtual void Verify() { |
| 192 // Make sure the two id's we expect to be blacklisted are. | 216 // Make sure the two id's we expect to be blacklisted are. |
| 193 EXPECT_TRUE(prefs()->IsExtensionBlacklisted(extensions_[0]->id())); | 217 EXPECT_TRUE(prefs()->IsExtensionBlacklisted(extensions_[0]->id())); |
| 194 EXPECT_TRUE(prefs()->IsExtensionBlacklisted(not_installed_id_)); | 218 EXPECT_TRUE(prefs()->IsExtensionBlacklisted(not_installed_id_)); |
| 195 | 219 |
| 196 // Make sure the other id's are not blacklisted. | 220 // Make sure the other id's are not blacklisted. |
| 197 ExtensionList::const_iterator iter; | 221 ExtensionList::const_iterator iter; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 EXPECT_TRUE(prefs()->IsIncognitoEnabled(extension_->id())); | 353 EXPECT_TRUE(prefs()->IsIncognitoEnabled(extension_->id())); |
| 330 } | 354 } |
| 331 | 355 |
| 332 private: | 356 private: |
| 333 scoped_refptr<Extension> extension_; | 357 scoped_refptr<Extension> extension_; |
| 334 }; | 358 }; |
| 335 TEST_F(ExtensionPrefsOnExtensionInstalled, | 359 TEST_F(ExtensionPrefsOnExtensionInstalled, |
| 336 ExtensionPrefsOnExtensionInstalled) {} | 360 ExtensionPrefsOnExtensionInstalled) {} |
| 337 | 361 |
| 338 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { | 362 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { |
| 339 public: | 363 public: |
| 340 virtual void Initialize() { | 364 virtual void Initialize() { |
| 341 // No extensions yet. | 365 // No extensions yet. |
| 342 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex()); | 366 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex()); |
| 343 | 367 |
| 344 extension_ = prefs_.AddExtension("on_extension_installed"); | 368 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 345 EXPECT_EQ(Extension::ENABLED, | 369 EXPECT_EQ(Extension::ENABLED, |
| 346 prefs()->GetExtensionState(extension_->id())); | 370 prefs()->GetExtensionState(extension_->id())); |
| 347 prefs()->OnExtensionInstalled(extension_.get(), | 371 prefs()->OnExtensionInstalled(extension_.get(), |
| 348 Extension::ENABLED, false); | 372 Extension::ENABLED, false); |
| 349 } | 373 } |
| 350 | 374 |
| 351 virtual void Verify() { | 375 virtual void Verify() { |
| 352 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | 376 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); |
| 353 // Extension should have been assigned a launch index > 0. | 377 // Extension should have been assigned a launch index > 0. |
| 354 EXPECT_GT(launch_index, 0); | 378 EXPECT_GT(launch_index, 0); |
| 355 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex()); | 379 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex()); |
| 356 // Set a new launch index of one higher and verify. | 380 // Set a new launch index of one higher and verify. |
| 357 prefs()->SetAppLaunchIndex(extension_->id(), | 381 prefs()->SetAppLaunchIndex(extension_->id(), |
| 358 prefs()->GetNextAppLaunchIndex()); | 382 prefs()->GetNextAppLaunchIndex()); |
| 359 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); | 383 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); |
| 360 EXPECT_EQ(launch_index + 1, new_launch_index); | 384 EXPECT_EQ(launch_index + 1, new_launch_index); |
| 361 | 385 |
| 362 // This extension doesn't exist, so it should return -1. | 386 // This extension doesn't exist, so it should return -1. |
| 363 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); | 387 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); |
| 364 } | 388 } |
| 365 | 389 |
| 366 private: | 390 private: |
| 367 scoped_refptr<Extension> extension_; | 391 scoped_refptr<Extension> extension_; |
| 368 }; | 392 }; |
| 369 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} | 393 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} |
| 394 | |
| 395 namespace keys = extension_manifest_keys; | |
| 396 | |
| 397 // Use constants to avoid confusing std::map with hard-coded strings. | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
I don't understand? Constants are good, but not fo
battre (please use the other)
2010/11/19 16:03:18
just copy and pasted that comment. I have removed
| |
| 398 const char kPref1[] = "path1.subpath"; | |
| 399 const char kPref2[] = "path2"; | |
| 400 const char kPref3[] = "path3"; | |
| 401 const char kPref4[] = "path4"; | |
| 402 | |
| 403 // Default values in case an extension pref value is not overridden. | |
| 404 const char kDefaultPref1[] = "default pref 1"; | |
| 405 const char kDefaultPref2[] = "default pref 2"; | |
| 406 const char kDefaultPref3[] = "default pref 3"; | |
| 407 const char kDefaultPref4[] = "default pref 4"; | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
These declarations should be moved to the top of t
battre (please use the other)
2010/11/19 16:03:18
Moved it, but did not find anything in the style g
| |
| 408 | |
| 409 class ExtensionPrefsPreferencesBase : public ExtensionPrefsTest { | |
| 410 public: | |
| 411 ExtensionPrefsPreferencesBase() | |
| 412 : ExtensionPrefsTest(), | |
| 413 ext1(NULL), | |
| 414 ext2(NULL), | |
| 415 ext3(NULL), | |
| 416 installed() { | |
| 417 DictionaryValue simple_dict; | |
| 418 std::string error; | |
| 419 | |
| 420 simple_dict.SetString(keys::kVersion, "1.0.0.0"); | |
| 421 simple_dict.SetString(keys::kName, "unused"); | |
| 422 | |
| 423 ext1_scoped_ = Extension::Create( | |
| 424 prefs_.temp_dir().AppendASCII("ext1"), Extension::INVALID, | |
| 425 simple_dict, false, &error); | |
| 426 ext2_scoped_ = Extension::Create( | |
| 427 prefs_.temp_dir().AppendASCII("ext2"), Extension::INVALID, | |
| 428 simple_dict, false, &error); | |
| 429 ext3_scoped_ = Extension::Create( | |
| 430 prefs_.temp_dir().AppendASCII("ext3"), Extension::INVALID, | |
| 431 simple_dict, false, &error); | |
| 432 | |
| 433 ext1 = ext1_scoped_.get(); | |
| 434 ext2 = ext2_scoped_.get(); | |
| 435 ext3 = ext3_scoped_.get(); | |
| 436 | |
| 437 for (size_t i = 0; i < arraysize(installed); ++i) | |
| 438 installed[i] = false; | |
| 439 } | |
| 440 | |
| 441 void RegisterPreferences() { | |
| 442 prefs()->pref_service()->RegisterStringPref(kPref1, kDefaultPref1); | |
| 443 prefs()->pref_service()->RegisterStringPref(kPref2, kDefaultPref2); | |
| 444 prefs()->pref_service()->RegisterStringPref(kPref3, kDefaultPref3); | |
| 445 prefs()->pref_service()->RegisterStringPref(kPref4, kDefaultPref4); | |
| 446 } | |
| 447 | |
| 448 void InstallExtControlledPref(Extension *ext, | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Instead of shortening to Ext, why not just Install
battre (please use the other)
2010/11/19 16:03:18
Unfortunately, Extension Preferences have a differ
Mattias Nissler (ping if slow)
2010/11/19 16:52:20
I see.
| |
| 449 const std::string& key, | |
| 450 Value* val) { | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
fix indentation.
battre (please use the other)
2010/11/19 16:03:18
Done.
Mattias Nissler (ping if slow)
2010/11/19 16:52:20
Not done?
battre (please use the other)
2010/11/19 18:00:39
Done.
| |
| 451 // Install extension the first time a preference is set for it. | |
| 452 Extension* extensions[] = {ext1, ext2, ext3}; | |
| 453 for (int i = 0; i < 3; ++i) { | |
| 454 if (ext == extensions[i] && !installed[i]) { | |
| 455 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, true); | |
| 456 installed[i] = true; | |
| 457 break; | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 prefs()->SetExtensionControlledPref(ext->id(), key, val); | |
| 462 } | |
| 463 | |
| 464 void UninstallExtension(const std::string& extension_id) { | |
| 465 prefs()->OnExtensionUninstalled(extension_id, Extension::INTERNAL, false); | |
| 466 } | |
| 467 | |
| 468 // Weak references, for convenience. | |
| 469 Extension* ext1; | |
| 470 Extension* ext2; | |
| 471 Extension* ext3; | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Missing trailing _
battre (please use the other)
2010/11/19 16:03:18
Was just copy&pasted, but changed now.
Done.
Mattias Nissler (ping if slow)
2010/11/19 16:52:20
Not done?
battre (please use the other)
2010/11/19 18:00:39
Done.
| |
| 472 | |
| 473 // Flags indicating whether each of the extensions has been installed, yet. | |
| 474 bool installed[3]; | |
| 475 | |
| 476 private: | |
| 477 scoped_refptr<Extension> ext1_scoped_; | |
| 478 scoped_refptr<Extension> ext2_scoped_; | |
| 479 scoped_refptr<Extension> ext3_scoped_; | |
| 480 }; | |
| 481 | |
| 482 class ExtensionPrefsInstallOneExtension | |
| 483 : public ExtensionPrefsPreferencesBase { | |
| 484 virtual void Initialize() { | |
| 485 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 486 } | |
| 487 virtual void Verify() { | |
| 488 std::string actual = prefs()->pref_service()->GetString(kPref1); | |
| 489 EXPECT_EQ("val1", actual); | |
| 490 } | |
| 491 }; | |
| 492 TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {} | |
| 493 | |
| 494 // Make sure the last-installed extension wins. | |
| 495 class ExtensionPrefsInstallMultipleExtensions | |
| 496 : public ExtensionPrefsPreferencesBase { | |
| 497 virtual void Initialize() { | |
| 498 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 499 InstallExtControlledPref(ext2, kPref1, Value::CreateStringValue("val2")); | |
| 500 InstallExtControlledPref(ext3, kPref1, Value::CreateStringValue("val3")); | |
| 501 } | |
| 502 virtual void Verify() { | |
| 503 std::string actual = prefs()->pref_service()->GetString(kPref1); | |
| 504 EXPECT_EQ("val3", actual); | |
| 505 } | |
| 506 }; | |
| 507 TEST_F(ExtensionPrefsInstallMultipleExtensions, | |
| 508 ExtensionPrefsInstallMultipleExtensions) {} | |
| 509 | |
| 510 // Make sure the last-installed extension wins for each preference. | |
| 511 class ExtensionPrefsInstallOverwrittenExtensions | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
I could argue that this test case covers also what
battre (please use the other)
2010/11/19 16:03:18
Done.
Mattias Nissler (ping if slow)
2010/11/19 16:52:20
No change?
battre (please use the other)
2010/11/19 18:00:39
Done.
| |
| 512 : public ExtensionPrefsPreferencesBase { | |
| 513 virtual void Initialize() { | |
| 514 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 515 InstallExtControlledPref(ext2, kPref1, Value::CreateStringValue("val2")); | |
| 516 InstallExtControlledPref(ext3, kPref1, Value::CreateStringValue("val3")); | |
| 517 | |
| 518 InstallExtControlledPref(ext1, kPref2, Value::CreateStringValue("val4")); | |
| 519 InstallExtControlledPref(ext2, kPref2, Value::CreateStringValue("val5")); | |
| 520 | |
| 521 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val6")); | |
| 522 InstallExtControlledPref(ext1, kPref2, Value::CreateStringValue("val7")); | |
| 523 InstallExtControlledPref(ext1, kPref3, Value::CreateStringValue("val8")); | |
| 524 } | |
| 525 virtual void Verify() { | |
| 526 std::string actual; | |
| 527 actual = prefs()->pref_service()->GetString(kPref1); | |
| 528 EXPECT_EQ("val3", actual); | |
| 529 actual = prefs()->pref_service()->GetString(kPref2); | |
| 530 EXPECT_EQ("val5", actual); | |
| 531 actual = prefs()->pref_service()->GetString(kPref3); | |
| 532 EXPECT_EQ("val8", actual); | |
| 533 } | |
| 534 }; | |
| 535 TEST_F(ExtensionPrefsInstallOverwrittenExtensions, | |
| 536 ExtensionPrefsInstallOverwrittenExtensions) {} | |
| 537 | |
| 538 // Make sure the last-installed extension wins even if other extensions set | |
| 539 // the same or different preferences later. | |
| 540 class ExtensionPrefsInstallInterleavedExtensions | |
| 541 : public ExtensionPrefsPreferencesBase { | |
| 542 virtual void Initialize() { | |
| 543 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 544 InstallExtControlledPref(ext2, kPref2, Value::CreateStringValue("val2")); | |
| 545 InstallExtControlledPref(ext3, kPref3, Value::CreateStringValue("val3")); | |
| 546 | |
| 547 InstallExtControlledPref(ext3, kPref3, Value::CreateStringValue("val4")); | |
| 548 InstallExtControlledPref(ext2, kPref3, Value::CreateStringValue("val5")); | |
| 549 InstallExtControlledPref(ext1, kPref3, Value::CreateStringValue("val6")); | |
| 550 | |
| 551 InstallExtControlledPref(ext3, kPref1, Value::CreateStringValue("val7")); | |
| 552 } | |
| 553 virtual void Verify() { | |
| 554 std::string actual; | |
| 555 actual = prefs()->pref_service()->GetString(kPref1); | |
| 556 EXPECT_EQ("val7", actual); | |
| 557 actual = prefs()->pref_service()->GetString(kPref2); | |
| 558 EXPECT_EQ("val2", actual); | |
| 559 actual = prefs()->pref_service()->GetString(kPref3); | |
| 560 EXPECT_EQ("val4", actual); | |
| 561 } | |
| 562 }; | |
| 563 TEST_F(ExtensionPrefsInstallInterleavedExtensions, | |
| 564 ExtensionPrefsInstallInterleavedExtensions) {} | |
| 565 | |
| 566 class ExtensionPrefsUninstallOnlyExtension | |
| 567 : public ExtensionPrefsPreferencesBase { | |
| 568 virtual void Initialize() { | |
| 569 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 570 InstallExtControlledPref(ext1, kPref2, Value::CreateStringValue("val2")); | |
| 571 | |
| 572 UninstallExtension(ext1->id()); | |
| 573 } | |
| 574 virtual void Verify() { | |
| 575 std::string actual; | |
| 576 actual = prefs()->pref_service()->GetString(kPref1); | |
| 577 EXPECT_EQ(kDefaultPref1, actual); | |
| 578 actual = prefs()->pref_service()->GetString(kPref2); | |
| 579 EXPECT_EQ(kDefaultPref2, actual); | |
| 580 } | |
| 581 }; | |
| 582 TEST_F(ExtensionPrefsUninstallOnlyExtension, | |
| 583 ExtensionPrefsUninstallOnlyExtension) {} | |
| 584 | |
| 585 // Tests uninstalling an extension that wasn't winning for any preferences. | |
| 586 class ExtensionPrefsUninstallIrrelevantExtension | |
| 587 : public ExtensionPrefsPreferencesBase { | |
| 588 virtual void Initialize() { | |
| 589 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 590 InstallExtControlledPref(ext2, kPref1, Value::CreateStringValue("val2")); | |
| 591 | |
| 592 InstallExtControlledPref(ext1, kPref2, Value::CreateStringValue("val3")); | |
| 593 InstallExtControlledPref(ext2, kPref2, Value::CreateStringValue("val4")); | |
| 594 | |
| 595 UninstallExtension(ext1->id()); | |
| 596 } | |
| 597 virtual void Verify() { | |
| 598 std::string actual; | |
| 599 actual = prefs()->pref_service()->GetString(kPref1); | |
| 600 EXPECT_EQ("val2", actual); | |
| 601 actual = prefs()->pref_service()->GetString(kPref2); | |
| 602 EXPECT_EQ("val4", actual); | |
| 603 } | |
| 604 }; | |
| 605 TEST_F(ExtensionPrefsUninstallIrrelevantExtension, | |
| 606 ExtensionPrefsUninstallIrrelevantExtension) {} | |
| 607 | |
| 608 // Tests uninstalling an extension that was winning for all preferences. | |
| 609 class ExtensionPrefsUninstallExtensionFromTop | |
| 610 : public ExtensionPrefsPreferencesBase { | |
| 611 virtual void Initialize() { | |
| 612 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 613 InstallExtControlledPref(ext2, kPref1, Value::CreateStringValue("val2")); | |
| 614 InstallExtControlledPref(ext3, kPref1, Value::CreateStringValue("val3")); | |
| 615 | |
| 616 InstallExtControlledPref(ext1, kPref2, Value::CreateStringValue("val4")); | |
| 617 InstallExtControlledPref(ext3, kPref2, Value::CreateStringValue("val5")); | |
| 618 | |
| 619 UninstallExtension(ext3->id()); | |
| 620 } | |
| 621 virtual void Verify() { | |
| 622 std::string actual; | |
| 623 actual = prefs()->pref_service()->GetString(kPref1); | |
| 624 EXPECT_EQ("val2", actual); | |
| 625 actual = prefs()->pref_service()->GetString(kPref2); | |
| 626 EXPECT_EQ("val4", actual); | |
| 627 } | |
| 628 }; | |
| 629 TEST_F(ExtensionPrefsUninstallExtensionFromTop, | |
| 630 ExtensionPrefsUninstallExtensionFromTop) {} | |
| 631 | |
| 632 // Tests uninstalling an extension that was winning for only some preferences. | |
| 633 class ExtensionPrefsUninstallExtensionFromMiddle | |
| 634 : public ExtensionPrefsPreferencesBase { | |
| 635 virtual void Initialize() { | |
| 636 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 637 InstallExtControlledPref(ext2, kPref1, Value::CreateStringValue("val2")); | |
| 638 InstallExtControlledPref(ext3, kPref1, Value::CreateStringValue("val3")); | |
| 639 | |
| 640 InstallExtControlledPref(ext1, kPref2, Value::CreateStringValue("val4")); | |
| 641 InstallExtControlledPref(ext2, kPref2, Value::CreateStringValue("val5")); | |
| 642 | |
| 643 InstallExtControlledPref(ext1, kPref3, Value::CreateStringValue("val6")); | |
| 644 | |
| 645 InstallExtControlledPref(ext2, kPref4, Value::CreateStringValue("val7")); | |
| 646 | |
| 647 UninstallExtension(ext2->id()); | |
| 648 } | |
| 649 virtual void Verify() { | |
| 650 std::string actual; | |
| 651 actual = prefs()->pref_service()->GetString(kPref1); | |
| 652 EXPECT_EQ("val3", actual); | |
| 653 actual = prefs()->pref_service()->GetString(kPref2); | |
| 654 EXPECT_EQ("val4", actual); | |
| 655 actual = prefs()->pref_service()->GetString(kPref3); | |
| 656 EXPECT_EQ("val6", actual); | |
| 657 actual = prefs()->pref_service()->GetString(kPref4); | |
| 658 EXPECT_EQ(kDefaultPref4, actual); | |
| 659 } | |
| 660 }; | |
| 661 TEST_F(ExtensionPrefsUninstallExtensionFromMiddle, | |
| 662 ExtensionPrefsUninstallExtensionFromMiddle) {} | |
| 663 | |
| 664 // Tests uninstalling an extension that was winning for only some preferences. | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Update comment.
battre (please use the other)
2010/11/19 16:03:18
Done.
Mattias Nissler (ping if slow)
2010/11/19 16:52:20
Not done?
battre (please use the other)
2010/11/19 18:00:39
Done.
| |
| 665 class ExtensionPrefsNotifyWhenNeeded | |
| 666 : public ExtensionPrefsPreferencesBase { | |
| 667 virtual void Initialize() { | |
| 668 using testing::_; | |
| 669 using testing::Mock; | |
| 670 using testing::StrEq; | |
| 671 | |
| 672 scoped_ptr<MockObserver> observer(new MockObserver()); | |
| 673 PrefChangeRegistrar registrar; | |
| 674 registrar.Init(prefs()->pref_service()); | |
| 675 registrar.Add(kPref1, observer.get()); | |
| 676 | |
| 677 EXPECT_CALL(*observer, Observe(_, _, _)); | |
| 678 InstallExtControlledPref(ext1, kPref1, | |
| 679 Value::CreateStringValue("https://www.chromium.org")); | |
| 680 Mock::VerifyAndClearExpectations(observer.get()); | |
| 681 | |
| 682 EXPECT_CALL(*observer, Observe(_, _, _)).Times(0); | |
| 683 InstallExtControlledPref(ext1, kPref1, | |
| 684 Value::CreateStringValue("https://www.chromium.org")); | |
| 685 Mock::VerifyAndClearExpectations(observer.get()); | |
| 686 | |
| 687 EXPECT_CALL(*observer, Observe(_, _, _)).Times(2); | |
| 688 InstallExtControlledPref(ext1, kPref1, | |
| 689 Value::CreateStringValue("chrome://newtab")); | |
| 690 | |
| 691 UninstallExtension(ext1->id()); | |
| 692 registrar.Remove(kPref1, observer.get()); | |
| 693 } | |
| 694 virtual void Verify() { | |
| 695 std::string actual = prefs()->pref_service()->GetString(kPref1); | |
| 696 EXPECT_EQ(kDefaultPref1, actual); | |
| 697 } | |
| 698 }; | |
| 699 TEST_F(ExtensionPrefsNotifyWhenNeeded, | |
| 700 ExtensionPrefsNotifyWhenNeeded) {} | |
| 701 | |
| 702 // Tests disabling an extension | |
| 703 class ExtensionPrefsDisableExt | |
| 704 : public ExtensionPrefsPreferencesBase { | |
| 705 virtual void Initialize() { | |
| 706 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 707 std::string actual = prefs()->pref_service()->GetString(kPref1); | |
| 708 EXPECT_EQ("val1", actual); | |
| 709 prefs()->SetExtensionState(ext1, Extension::DISABLED); | |
| 710 } | |
| 711 virtual void Verify() { | |
| 712 std::string actual = prefs()->pref_service()->GetString(kPref1); | |
| 713 EXPECT_EQ(kDefaultPref1, actual); | |
| 714 } | |
| 715 }; | |
| 716 TEST_F(ExtensionPrefsDisableExt, ExtensionPrefsDisableExt) {} | |
| 717 | |
| 718 // Tests disabling and reenabling an extension | |
| 719 class ExtensionPrefsReenableExt | |
| 720 : public ExtensionPrefsPreferencesBase { | |
| 721 virtual void Initialize() { | |
| 722 InstallExtControlledPref(ext1, kPref1, Value::CreateStringValue("val1")); | |
| 723 prefs()->SetExtensionState(ext1, Extension::DISABLED); | |
| 724 prefs()->SetExtensionState(ext1, Extension::ENABLED); | |
| 725 } | |
| 726 virtual void Verify() { | |
| 727 std::string actual = prefs()->pref_service()->GetString(kPref1); | |
| 728 EXPECT_EQ("val1", actual); | |
| 729 } | |
| 730 }; | |
| 731 TEST_F(ExtensionPrefsDisableExt, ExtensionPrefsReenableExt) {} | |
| 732 | |
|
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
No trailing newlines please.
battre (please use the other)
2010/11/19 16:03:18
Hopefully done. Eclipse messes this up.
Mattias Nissler (ping if slow)
2010/11/19 16:52:20
I see, not a big deal :)
However, you should get t
| |
| OLD | NEW |