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

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: Fixed comiler errors Created 8 years, 10 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..eb6a248edf87031a372565017dd12164968f5feb
--- /dev/null
+++ b/chrome/browser/extensions/api/declarative/declarative_apitest.cc
@@ -0,0 +1,62 @@
+// 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/api/declarative/rules_registry_service.h"
+#include "chrome/browser/extensions/api/declarative/test_rules_registry.h"
+#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension.h"
+
+using namespace extensions;
+
+namespace {
+const char kTestEvent[] = "webRequest.onRequest";
+} // 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() {
+ Profile* profile = browser()->profile();
+ RulesRegistryService* rules_registry =
+ profile->GetExtensionService()->GetRulesRegistryService();
+ scoped_ptr<RulesRegistry> test_rules_registry(new TestRulesRegistry());
+ test_rules_registry_ = test_rules_registry.get();
+ // TODO(battre): Remove this, once we have a real implementation for a
+ // RulesRegistry.
+ rules_registry->RegisterRulesRegistry(kTestEvent,
+ test_rules_registry.Pass());
+ }
+
+ // Weak pointer that is deleted when the profile is destroyed.
+ 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