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

Unified Diff: chrome/browser/extensions/api/declarative/declarative_apitest.cc

Issue 9315010: RulesRegistry for declarative APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implemented ID and priority generation Created 8 years, 11 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/api/declarative/declarative_apitest.cc
diff --git a/chrome/browser/extensions/api/declarative/declarative_apitest.cc b/chrome/browser/extensions/api/declarative/declarative_apitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2d530ced40c695c8bd7ac8bbfe188fbe21221b58
--- /dev/null
+++ b/chrome/browser/extensions/api/declarative/declarative_apitest.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
+#include "chrome/browser/extensions/api/declarative/rules_registry_service_factory.h"
+#include "chrome/browser/extensions/api/declarative/test_rules_registry.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension.h"
+
+namespace {
+const char kTestEvent[] = "experimental.declarative.testEvent";
+} // namespace
+
+class DeclarativeApiTest : public ExtensionApiTest {
+ public:
+ DeclarativeApiTest() : test_rules_registry_(NULL) {}
+ virtual ~DeclarativeApiTest() {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ ExtensionApiTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
+ }
+
+ void RegisterTestRuleRegistry() {
+ using namespace extensions;
+ Profile* profile = browser()->profile();
+ RulesRegistryService* rules_registry =
+ RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile);
+ scoped_ptr<RulesRegistry> test_rules_registry(new TestRulesRegistry());
+ test_rules_registry_ = test_rules_registry.get();
+ rules_registry->RegisterRuleRegistry(kTestEvent,
+ test_rules_registry.Pass());
+ }
+
+ // Weak pointer that is deleted when the profile is destroyed.
+ extensions::RulesRegistry* test_rules_registry_;
+};
+
+IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) {
+ RegisterTestRuleRegistry();
+ ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_;
+
+ // Check that unloading the page has removed all rules.
+ std::string extension_id = GetSingleLoadedExtension()->id();
+ UnloadExtension(extension_id);
+
+ std::vector<std::string> rule_identifiers; // Empty to get all rules.
+ std::vector<DictionaryValue*> known_rules;
+ test_rules_registry_->GetRules(extension_id,
+ rule_identifiers,
+ &known_rules);
+ EXPECT_TRUE(known_rules.empty());
+}

Powered by Google App Engine
This is Rietveld 408576698