Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / active_tab_apitest.cc
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/api/extension_action/extension_action_api.h"
7 #include "chrome/browser/extensions/extension_apitest.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 "extensions/test/result_catcher.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13
14 namespace extensions {
15 namespace {
16
17 // Times out on win syzyasan, http://crbug.com/166026
18 #if defined(SYZYASAN)
19 #define MAYBE_ActiveTab DISABLED_ActiveTab
20 #else
21 #define MAYBE_ActiveTab ActiveTab
22 #endif
23 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ActiveTab) {
24   ASSERT_TRUE(StartEmbeddedTestServer());
25
26   const Extension* extension =
27       LoadExtension(test_data_dir_.AppendASCII("active_tab"));
28   ASSERT_TRUE(extension);
29
30   // Shouldn't be initially granted based on activeTab.
31   {
32     ResultCatcher catcher;
33     ui_test_utils::NavigateToURL(
34         browser(),
35         embedded_test_server()->GetURL(
36             "/extensions/api_test/active_tab/page.html"));
37     EXPECT_TRUE(catcher.GetNextResult()) << message_;
38   }
39
40   // Granting to the extension should give it access to page.html.
41   {
42     ResultCatcher catcher;
43     ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction(
44         extension, browser(), true);
45     EXPECT_TRUE(catcher.GetNextResult()) << message_;
46   }
47
48   // Changing page should go back to it not having access.
49   {
50     ResultCatcher catcher;
51     ui_test_utils::NavigateToURL(
52         browser(),
53         embedded_test_server()->GetURL(
54             "/extensions/api_test/active_tab/final_page.html"));
55     EXPECT_TRUE(catcher.GetNextResult()) << message_;
56   }
57 }
58
59 }  // namespace
60 }  // namespace extensions