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

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

Issue 8177022: Add onChanged events to the extension settings API, both from sync and between (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_settings_apitest.cc
diff --git a/chrome/browser/extensions/extension_settings_apitest.cc b/chrome/browser/extensions/extension_settings_apitest.cc
index 213d921961b82e5897d41c88cec4bb6710f0a68a..ad1a1fb420473ee8dc1d485d1bcc33920cca2bf9 100644
--- a/chrome/browser/extensions/extension_settings_apitest.cc
+++ b/chrome/browser/extensions/extension_settings_apitest.cc
@@ -2,15 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/json/json_writer.h"
#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_settings_backend.h"
+#include "chrome/browser/extensions/extension_settings_sync_util.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/api/sync_change.h"
+#include "chrome/browser/sync/api/sync_change_processor.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
+namespace {
+
+class NoopSyncChangeProcessor : public SyncChangeProcessor {
+ public:
+ virtual SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const SyncChangeList& change_list) OVERRIDE {
+ return SyncError();
+ }
+
+ virtual ~NoopSyncChangeProcessor() {};
+};
+
+} // namespace
+
class ExtensionSettingsApiTest : public ExtensionApiTest {
protected:
void ReplyWhenSatisfied(
@@ -20,11 +41,11 @@ class ExtensionSettingsApiTest : public ExtensionApiTest {
normal_action, incognito_action, NULL, false);
}
- void LoadAndReplyWhenSatisfied(
+ const Extension* LoadAndReplyWhenSatisfied(
const std::string& normal_action,
const std::string& incognito_action,
const std::string& extension_dir) {
- MaybeLoadAndReplyWhenSatisfied(
+ return MaybeLoadAndReplyWhenSatisfied(
normal_action, incognito_action, &extension_dir, false);
}
@@ -34,8 +55,26 @@ class ExtensionSettingsApiTest : public ExtensionApiTest {
MaybeLoadAndReplyWhenSatisfied(normal_action, incognito_action, NULL, true);
}
+ void InitSync(SyncChangeProcessor* sync_processor) {
+ browser()->profile()->GetExtensionService()->
+ extension_settings_frontend()->RunWithBackend(base::Bind(
+ &ExtensionSettingsApiTest::InitSyncWithBackend,
+ this,
+ sync_processor));
+ MessageLoop::current()->RunAllPending();
+ }
+
+ void SendChanges(const SyncChangeList& change_list) {
+ browser()->profile()->GetExtensionService()->
+ extension_settings_frontend()->RunWithBackend(base::Bind(
+ &ExtensionSettingsApiTest::SendChangesToBackend,
+ this,
+ change_list));
+ MessageLoop::current()->RunAllPending();
+ }
+
private:
- void MaybeLoadAndReplyWhenSatisfied(
+ const Extension* MaybeLoadAndReplyWhenSatisfied(
const std::string& normal_action,
const std::string& incognito_action,
// May be NULL to imply not loading the extension.
@@ -46,9 +85,11 @@ class ExtensionSettingsApiTest : public ExtensionApiTest {
// Only load the extension after the listeners have been set up, to avoid
// initialisation race conditions.
+ const Extension* extension = NULL;
if (extension_dir) {
- ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
- .AppendASCII("settings").AppendASCII(*extension_dir)));
+ extension = LoadExtensionIncognito(
+ test_data_dir_.AppendASCII("settings").AppendASCII(*extension_dir));
+ EXPECT_TRUE(extension);
}
EXPECT_TRUE(listener.WaitUntilSatisfied());
@@ -56,6 +97,7 @@ class ExtensionSettingsApiTest : public ExtensionApiTest {
listener.Reply(CreateMessage(normal_action, is_final_action));
listener_incognito.Reply(CreateMessage(incognito_action, is_final_action));
+ return extension;
}
std::string CreateMessage(const std::string& action, bool is_final_action) {
@@ -66,6 +108,19 @@ class ExtensionSettingsApiTest : public ExtensionApiTest {
base::JSONWriter::Write(message.get(), false, &message_json);
return message_json;
}
+
+ void InitSyncWithBackend(
+ SyncChangeProcessor* sync_processor, ExtensionSettingsBackend* backend) {
+ EXPECT_FALSE(backend->MergeDataAndStartSyncing(
+ syncable::EXTENSION_SETTINGS,
+ SyncDataList(),
+ sync_processor).IsSet());
+ }
+
+ void SendChangesToBackend(
+ const SyncChangeList& change_list, ExtensionSettingsBackend* backend) {
+ EXPECT_FALSE(backend->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
+ }
};
IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SimpleTest) {
@@ -90,15 +145,93 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SplitModeIncognito) {
browser()->profile()->GetOffTheRecordProfile());
LoadAndReplyWhenSatisfied("assertEmpty", "assertEmpty", "split_incognito");
- ReplyWhenSatisfied("noop", "setFoobar");
- ReplyWhenSatisfied("assertFoobar", "assertFoobar");
+ ReplyWhenSatisfied("noop", "setFoo");
+ ReplyWhenSatisfied("assertFoo", "assertFoo");
ReplyWhenSatisfied("clear", "noop");
ReplyWhenSatisfied("assertEmpty", "assertEmpty");
- ReplyWhenSatisfied("setFoobar", "noop");
- ReplyWhenSatisfied("assertFoobar", "assertFoobar");
+ ReplyWhenSatisfied("setFoo", "noop");
+ ReplyWhenSatisfied("assertFoo", "assertFoo");
ReplyWhenSatisfied("noop", "removeFoo");
FinalReplyWhenSatisfied("assertEmpty", "assertEmpty");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
}
+
+IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
+ OnChangedNotificationsBetweenBackgroundPages) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableExperimentalExtensionApis);
+
+ // We need 2 ResultCatchers because we'll be running the same test in both
+ // regular and incognito mode.
+ ResultCatcher catcher, catcher_incognito;
+ catcher.RestrictToProfile(browser()->profile());
+ catcher_incognito.RestrictToProfile(
+ browser()->profile()->GetOffTheRecordProfile());
+
+ LoadAndReplyWhenSatisfied(
+ "assertNoNotifications", "assertNoNotifications", "split_incognito");
+ ReplyWhenSatisfied("noop", "setFoo");
+ ReplyWhenSatisfied("assertAddFooNotification", "assertNoNotifications");
+ ReplyWhenSatisfied("clearNotifications", "noop");
+ ReplyWhenSatisfied("removeFoo", "noop");
+ FinalReplyWhenSatisfied(
+ "assertNoNotifications", "assertDeleteFooNotification");
+
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+ EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
+}
+
+#if defined(OS_WIN)
+// Very flaky on Windows, so just disable. crbug.com/101110
+#define MAYBE_OnChangedNotificationsFromSync \
+ DISABLED_OnChangedNotificationsFromSync
+#else
+// Possibly flaky on other platforms, though haven't observed it yet.
+#define MAYBE_OnChangedNotificationsFromSync \
+ FLAKY_OnChangedNotificationsFromSync
+#endif
+
+IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
+ MAYBE_OnChangedNotificationsFromSync) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableExperimentalExtensionApis);
+
+ // We need 2 ResultCatchers because we'll be running the same test in both
+ // regular and incognito mode.
+ ResultCatcher catcher, catcher_incognito;
+ catcher.RestrictToProfile(browser()->profile());
+ catcher_incognito.RestrictToProfile(
+ browser()->profile()->GetOffTheRecordProfile());
+
+ const Extension* extension =
+ LoadAndReplyWhenSatisfied(
+ "assertNoNotifications", "assertNoNotifications", "split_incognito");
+ const std::string& extension_id = extension->id();
+
+ NoopSyncChangeProcessor sync_processor;
+ InitSync(&sync_processor);
+
+ // Set "foo" to "bar" via sync.
+ SyncChangeList sync_changes;
+ StringValue bar("bar");
+ sync_changes.push_back(extension_settings_sync_util::CreateAdd(
+ extension_id, "foo", bar));
+ SendChanges(sync_changes);
+
+ ReplyWhenSatisfied("assertAddFooNotification", "assertAddFooNotification");
+ ReplyWhenSatisfied("clearNotifications", "clearNotifications");
+
+ // Remove "foo" via sync.
+ sync_changes.clear();
+ sync_changes.push_back(extension_settings_sync_util::CreateDelete(
+ extension_id, "foo"));
+ SendChanges(sync_changes);
+
+ FinalReplyWhenSatisfied(
+ "assertDeleteFooNotification", "assertDeleteFooNotification");
+
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+ EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
+}
« no previous file with comments | « chrome/browser/extensions/extension_settings_api.cc ('k') | chrome/browser/extensions/extension_settings_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698