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

Unified Diff: chrome/browser/extensions/extension_prefs_unittest.cc

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 10 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_prefs_unittest.cc
diff --git a/chrome/browser/extensions/extension_prefs_unittest.cc b/chrome/browser/extensions/extension_prefs_unittest.cc
index 6b59740e9307d2c7cc2d2814145b42124ba4df47..44986548fb30b1d1c81d02a81e02d8f95ead698d 100644
--- a/chrome/browser/extensions/extension_prefs_unittest.cc
+++ b/chrome/browser/extensions/extension_prefs_unittest.cc
@@ -591,20 +591,27 @@ class ExtensionPrefsPreferencesBase : public ExtensionPrefsTest {
void InstallExtControlledPref(Extension *ext,
const std::string& key,
Value* val) {
- // Install extension the first time a preference is set for it.
+ EnsureExtensionInstalled(ext);
+ const bool incognito = false;
+ prefs()->SetExtensionControlledPref(ext->id(), key, incognito, val);
+ }
+
+ void InstallExtControlledPrefIncognito(Extension *ext,
+ const std::string& key,
+ Value* val) {
+ EnsureExtensionInstalled(ext);
+ const bool incognito = true;
+ prefs()->SetExtensionControlledPref(ext->id(), key, incognito, val);
+ }
+
+ void UninstallExtension(const std::string& extension_id) {
Extension* extensions[] = {ext1_, ext2_, ext3_};
for (int i = 0; i < 3; ++i) {
- if (ext == extensions[i] && !installed[i]) {
- prefs()->OnExtensionInstalled(ext, Extension::ENABLED, true);
- installed[i] = true;
+ if (extensions[i]->id() == extension_id) {
+ installed[i] = false;
break;
}
}
-
- prefs()->SetExtensionControlledPref(ext->id(), key, val);
- }
-
- void UninstallExtension(const std::string& extension_id) {
prefs()->OnExtensionUninstalled(extension_id, Extension::INTERNAL, false);
}
@@ -617,6 +624,18 @@ class ExtensionPrefsPreferencesBase : public ExtensionPrefsTest {
bool installed[3];
private:
+ void EnsureExtensionInstalled(Extension *ext) {
+ // Install extension the first time a preference is set for it.
+ Extension* extensions[] = {ext1_, ext2_, ext3_};
+ for (int i = 0; i < 3; ++i) {
+ if (ext == extensions[i] && !installed[i]) {
+ prefs()->OnExtensionInstalled(ext, Extension::ENABLED, true);
+ installed[i] = true;
+ break;
+ }
+ }
+ }
+
scoped_refptr<Extension> ext1_scoped_;
scoped_refptr<Extension> ext2_scoped_;
scoped_refptr<Extension> ext3_scoped_;
@@ -634,6 +653,36 @@ class ExtensionPrefsInstallOneExtension
};
TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {}
+// Check that we forget incognito values after a reload.
+class ExtensionPrefsInstallIncognito
+ : public ExtensionPrefsPreferencesBase {
+ public:
+ ExtensionPrefsInstallIncognito() : iteration(0) {}
+
+ virtual void Initialize() {
+ InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1"));
+ InstallExtControlledPrefIncognito(ext1_, kPref1,
+ Value::CreateStringValue("val2"));
+ std::string actual = prefs_.incognito_pref_service()->GetString(kPref1);
+ EXPECT_EQ("val2", actual);
+ }
+ virtual void Verify() {
+ // main pref service shall see only non-incognito settings
+ std::string actual = prefs()->pref_service()->GetString(kPref1);
+ EXPECT_EQ("val1", actual);
+ // incognito pref service shall see incognito values only during first run
+ actual = prefs_.incognito_pref_service()->GetString(kPref1);
+ if (iteration == 0) {
+ EXPECT_EQ("val2", actual);
+ } else {
+ EXPECT_EQ("val1", actual);
+ }
+ ++iteration;
+ }
+ int iteration;
danno 2010/12/22 10:48:21 should be iteration_
battre 2010/12/22 18:34:53 Done.
+};
+TEST_F(ExtensionPrefsInstallIncognito, ExtensionPrefsInstallOneExtension) {}
+
// Make sure the last-installed extension wins for each preference.
class ExtensionPrefsInstallOverwrittenExtensions
: public ExtensionPrefsPreferencesBase {
@@ -662,6 +711,70 @@ class ExtensionPrefsInstallOverwrittenExtensions
TEST_F(ExtensionPrefsInstallOverwrittenExtensions,
ExtensionPrefsInstallOverwrittenExtensions) {}
+// Make sure the last-installed extension wins for each preference.
+class ExtensionPrefsInstallOverwrittenExtensionsIncognito
+ : public ExtensionPrefsPreferencesBase {
+ virtual void Initialize() {
+ const char* strings[] = {
+ kDefaultPref1,
+ "val1",
+ "val2",
+ "val3",
+ "val4"
+ };
+ int values[][6] = {
+ // columns:
+ // 0: pref value of extension 1
+ // 1: pref value of extension 1 incognito
+ // 2: pref value of extension 2
+ // 3: pref value of extension 2 incognito
+ // 4: desired winner regular
+ // 5: desired winner incognito
+ // e.g. { 1, 0, 0, 4, 1, 4}, means:
+ // ext1 regular is set to "val1", ext2 incognito is set to "val4"
+ // --> the winning regular value is "val1", the winning incognito
+ // value is "val4".
+ { 1, 0, 0, 0, 1, 1},
+ { 1, 2, 0, 0, 1, 2},
+ { 1, 0, 3, 0, 3, 3},
+ { 1, 0, 0, 4, 1, 4},
+ { 1, 2, 3, 0, 3, 3}, // The last 3 here is intentional!
+ { 1, 2, 0, 4, 1, 4},
+ { 1, 2, 3, 4, 3, 4}
Mattias Nissler (ping if slow) 2010/12/22 12:09:03 How about using a struct with descriptive variable
battre 2010/12/22 18:34:53 Done.
+ };
+ InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1"));
+ for (size_t row = 0; row < arraysize(values); ++row) {
+ LOG(INFO) << "Testing row " << row;
+ UninstallExtension(ext1_->id());
+ UninstallExtension(ext2_->id());
+ if (values[row][0]) {
+ InstallExtControlledPref(
+ ext1_, kPref1, Value::CreateStringValue(strings[values[row][0]]));
+ }
+ if (values[row][1]) {
+ InstallExtControlledPrefIncognito(
+ ext1_, kPref1, Value::CreateStringValue(strings[values[row][1]]));
+ }
+ if (values[row][2]) {
+ InstallExtControlledPref(
+ ext2_, kPref1, Value::CreateStringValue(strings[values[row][2]]));
+ }
+ if (values[row][3]) {
+ InstallExtControlledPrefIncognito(
+ ext2_, kPref1, Value::CreateStringValue(strings[values[row][3]]));
+ }
+ std::string actual;
+ actual = prefs()->pref_service()->GetString(kPref1);
+ EXPECT_EQ(strings[values[row][4]], actual);
+ actual = prefs_.incognito_pref_service()->GetString(kPref1);
+ EXPECT_EQ(strings[values[row][5]], actual);
+ }
+ }
+ virtual void Verify() {}
+};
+TEST_F(ExtensionPrefsInstallOverwrittenExtensionsIncognito,
+ ExtensionPrefsInstallOverwrittenExtensionsIncognito) {}
+
// Make sure the last-installed extension wins even if other extensions set
// the same or different preferences later.
class ExtensionPrefsInstallInterleavedExtensions
@@ -681,10 +794,16 @@ class ExtensionPrefsInstallInterleavedExtensions
std::string actual;
actual = prefs()->pref_service()->GetString(kPref1);
EXPECT_EQ("val7", actual);
+ actual = prefs_.incognito_pref_service()->GetString(kPref1);
+ EXPECT_EQ("val7", actual);
actual = prefs()->pref_service()->GetString(kPref2);
EXPECT_EQ("val2", actual);
+ actual = prefs_.incognito_pref_service()->GetString(kPref2);
+ EXPECT_EQ("val2", actual);
actual = prefs()->pref_service()->GetString(kPref3);
EXPECT_EQ("val4", actual);
+ actual = prefs_.incognito_pref_service()->GetString(kPref3);
+ EXPECT_EQ("val4", actual);
}
};
TEST_F(ExtensionPrefsInstallInterleavedExtensions,
@@ -735,13 +854,26 @@ TEST_F(ExtensionPrefsUninstallIrrelevantExtension,
// Tests uninstalling an extension that was winning for all preferences.
class ExtensionPrefsUninstallExtensionFromTop
: public ExtensionPrefsPreferencesBase {
+ public:
+ ExtensionPrefsUninstallExtensionFromTop() : iteration(0) {}
+
virtual void Initialize() {
InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1"));
+ InstallExtControlledPrefIncognito(ext1_, kPref1,
+ Value::CreateStringValue("val1i"));
InstallExtControlledPref(ext2_, kPref1, Value::CreateStringValue("val2"));
+ InstallExtControlledPrefIncognito(ext2_, kPref1,
+ Value::CreateStringValue("val2i"));
InstallExtControlledPref(ext3_, kPref1, Value::CreateStringValue("val3"));
+ InstallExtControlledPrefIncognito(ext3_, kPref1,
+ Value::CreateStringValue("val3i"));
InstallExtControlledPref(ext1_, kPref2, Value::CreateStringValue("val4"));
+ InstallExtControlledPrefIncognito(ext1_, kPref2,
+ Value::CreateStringValue("val4i"));
InstallExtControlledPref(ext3_, kPref2, Value::CreateStringValue("val5"));
+ InstallExtControlledPrefIncognito(ext3_, kPref2,
+ Value::CreateStringValue("val5i"));
UninstallExtension(ext3_->id());
}
@@ -751,7 +883,14 @@ class ExtensionPrefsUninstallExtensionFromTop
EXPECT_EQ("val2", actual);
actual = prefs()->pref_service()->GetString(kPref2);
EXPECT_EQ("val4", actual);
+ // After the reload (iteration == 1) all incognito settings are forgotten.
+ actual = prefs_.incognito_pref_service()->GetString(kPref1);
+ EXPECT_EQ((iteration == 0 ? "val2i" : "val2"), actual);
+ actual = prefs_.incognito_pref_service()->GetString(kPref2);
+ EXPECT_EQ((iteration == 0 ? "val4i" : "val4"), actual);
+ ++iteration;
}
+ int iteration;
danno 2010/12/22 10:48:21 should be iteration_
battre 2010/12/22 18:34:53 Done.
};
TEST_F(ExtensionPrefsUninstallExtensionFromTop,
ExtensionPrefsUninstallExtensionFromTop) {}
@@ -876,15 +1015,27 @@ class ExtensionPrefsSetExtensionControlledPref
virtual void Initialize() {
MockStringValue* v1 = new MockStringValue("https://www.chromium.org");
MockStringValue* v2 = new MockStringValue("https://www.chromium.org");
+ MockStringValue* v1i = new MockStringValue("https://www.chromium.org");
+ MockStringValue* v2i = new MockStringValue("https://www.chromium.org");
// Ownership is taken, value shall not be deleted.
EXPECT_CALL(*v1, Die()).Times(0);
+ EXPECT_CALL(*v1i, Die()).Times(0);
InstallExtControlledPref(ext1_, kPref1, v1);
+ InstallExtControlledPrefIncognito(ext1_, kPref1, v1i);
testing::Mock::VerifyAndClearExpectations(v1);
+ testing::Mock::VerifyAndClearExpectations(v1i);
// Make sure there is no memory leak and both values are deleted.
- EXPECT_CALL(*v2, Die()).Times(1);
EXPECT_CALL(*v1, Die()).Times(1);
+ EXPECT_CALL(*v1i, Die()).Times(1);
+ EXPECT_CALL(*v2, Die()).Times(1);
+ EXPECT_CALL(*v2i, Die()).Times(1);
InstallExtControlledPref(ext1_, kPref1, v2);
+ InstallExtControlledPrefIncognito(ext1_, kPref1, v2i);
prefs_.RecreateExtensionPrefs();
+ testing::Mock::VerifyAndClearExpectations(v1);
+ testing::Mock::VerifyAndClearExpectations(v1i);
+ testing::Mock::VerifyAndClearExpectations(v2);
+ testing::Mock::VerifyAndClearExpectations(v2i);
}
virtual void Verify() {

Powered by Google App Engine
This is Rietveld 408576698