1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/bind.h" 6 #include "base/bind_helpers.h" 7 #include "base/command_line.h" 8 #include "base/memory/scoped_ptr.h" 9 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" 10 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h" 11 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h" 12 #include "chrome/browser/extensions/extension_apitest.h" 13 #include "chrome/browser/extensions/extension_system_factory.h" 14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/test/base/ui_test_utils.h" 18 #include "content/public/browser/browser_thread.h" 19 20 using extensions::RulesRegistry; 21 using extensions::RulesRegistryService; 22 using extensions::WebRequestRulesRegistry; 23 24 class DeclarativeApiTest : public ExtensionApiTest { 25 }; 26 27 IN_PROC_BROWSER_TEST_F(DeclarativeApiTest, DeclarativeApi) { 28 ASSERT_TRUE(RunExtensionTest("declarative/api")) << message_; 29 30 // Check that unloading the page has removed all rules. 31 std::string extension_id = GetSingleLoadedExtension()->id(); 32 UnloadExtension(extension_id); 33 34 // UnloadExtension posts a task to the owner thread of the extension 35 // to process this unloading. The next task to retrive all rules 36 // is therefore processed after the UnloadExtension task has been executed. 37 38 RulesRegistryService* rules_registry_service = 39 extensions::RulesRegistryService::Get(browser()->profile()); 40 scoped_refptr<RulesRegistry> rules_registry = 41 rules_registry_service->GetRulesRegistry( 42 extensions::declarative_webrequest_constants::kOnRequest); 43 44 std::vector<linked_ptr<RulesRegistry::Rule> > known_rules; 45 46 content::BrowserThread::PostTask( 47 rules_registry->owner_thread(), 48 FROM_HERE, 49 base::Bind(base::IgnoreResult(&RulesRegistry::GetAllRules), 50 rules_registry, extension_id, &known_rules)); 51 52 content::RunAllPendingInMessageLoop(rules_registry->owner_thread()); 53 54 EXPECT_TRUE(known_rules.empty()); 55 } 56