Home | History | Annotate | Download | only in extensions
      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/logging.h"
      6 #include "chrome/browser/extensions/extension_apitest.h"
      7 #include "chrome/browser/extensions/extension_toolbar_model.h"
      8 #include "chrome/browser/ui/browser.h"
      9 #include "chrome/test/base/ui_test_utils.h"
     10 #include "extensions/common/extension.h"
     11 #include "net/test/embedded_test_server/embedded_test_server.h"
     12 
     13 namespace extensions {
     14 namespace {
     15 
     16 // Times out on win syzyasan, http://crbug.com/166026
     17 #if defined(SYZYASAN)
     18 #define MAYBE_ActiveTab DISABLED_ActiveTab
     19 #else
     20 #define MAYBE_ActiveTab ActiveTab
     21 #endif
     22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ActiveTab) {
     23   ASSERT_TRUE(StartEmbeddedTestServer());
     24 
     25   const Extension* extension =
     26       LoadExtension(test_data_dir_.AppendASCII("active_tab"));
     27   ASSERT_TRUE(extension);
     28 
     29   ExtensionToolbarModel* toolbar_model =
     30       ExtensionToolbarModel::Get(browser()->profile());
     31 
     32   // Shouldn't be initially granted based on activeTab.
     33   {
     34     ResultCatcher catcher;
     35     ui_test_utils::NavigateToURL(
     36         browser(),
     37         embedded_test_server()->GetURL(
     38             "/extensions/api_test/active_tab/page.html"));
     39     EXPECT_TRUE(catcher.GetNextResult()) << message_;
     40   }
     41 
     42   // Granting to the extension should give it access to page.html.
     43   {
     44     ResultCatcher catcher;
     45     toolbar_model->ExecuteBrowserAction(extension, browser(), NULL, true);
     46     EXPECT_TRUE(catcher.GetNextResult()) << message_;
     47   }
     48 
     49   // Changing page should go back to it not having access.
     50   {
     51     ResultCatcher catcher;
     52     ui_test_utils::NavigateToURL(
     53         browser(),
     54         embedded_test_server()->GetURL(
     55             "/extensions/api_test/active_tab/final_page.html"));
     56     EXPECT_TRUE(catcher.GetNextResult()) << message_;
     57   }
     58 }
     59 
     60 }  // namespace
     61 }  // namespace extensions
     62