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

Side by Side Diff: chrome/browser/extensions/active_tab_apitest.cc

Issue 2871533002: [Test] Added a test for activeTab URL filtering (Closed)
Patch Set: Comments, nits, ScopedTestPublicSessionLoginState Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/active_tab/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "chrome/browser/extensions/extension_action_runner.h" 6 #include "chrome/browser/extensions/extension_action_runner.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_tab_util.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
11 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/test/extension_test_message_listener.h"
12 #include "extensions/test/result_catcher.h" 14 #include "extensions/test/result_catcher.h"
13 #include "net/test/embedded_test_server/embedded_test_server.h" 15 #include "net/test/embedded_test_server/embedded_test_server.h"
14 16
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/extensions/extension_tab_util_delegate_chromeo s.h"
19 #include "chromeos/login/scoped_test_public_session_login_state.h"
20 #endif
21
15 namespace extensions { 22 namespace extensions {
16 namespace { 23 namespace {
17 24
18 // Times out on win syzyasan, http://crbug.com/166026 25 // Times out on win syzyasan, http://crbug.com/166026
19 #if defined(SYZYASAN) 26 #if defined(SYZYASAN)
20 #define MAYBE_ActiveTab DISABLED_ActiveTab 27 #define MAYBE_ActiveTab DISABLED_ActiveTab
21 #else 28 #else
22 #define MAYBE_ActiveTab ActiveTab 29 #define MAYBE_ActiveTab ActiveTab
23 #endif 30 #endif
24 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ActiveTab) { 31 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ActiveTab) {
25 ASSERT_TRUE(StartEmbeddedTestServer()); 32 ASSERT_TRUE(StartEmbeddedTestServer());
26 33
27 const Extension* extension = 34 const Extension* extension =
28 LoadExtension(test_data_dir_.AppendASCII("active_tab")); 35 LoadExtension(test_data_dir_.AppendASCII("active_tab"));
29 ASSERT_TRUE(extension); 36 ASSERT_TRUE(extension);
30 37
31 // Shouldn't be initially granted based on activeTab. 38 // Shouldn't be initially granted based on activeTab.
32 { 39 {
33 ResultCatcher catcher; 40 ResultCatcher catcher;
34 ui_test_utils::NavigateToURL( 41 ui_test_utils::NavigateToURL(
35 browser(), 42 browser(),
36 embedded_test_server()->GetURL( 43 embedded_test_server()->GetURL(
37 "/extensions/api_test/active_tab/page.html")); 44 "/extensions/api_test/active_tab/page.html"));
38 EXPECT_TRUE(catcher.GetNextResult()) << message_; 45 EXPECT_TRUE(catcher.GetNextResult()) << message_;
39 } 46 }
40 47
48 // Do one pass of BrowserAction without granting activeTab permission,
49 // extension shouldn't have access to tab.url.
50 {
51 ResultCatcher catcher;
52 ExtensionActionRunner::GetForWebContents(
53 browser()->tab_strip_model()->GetActiveWebContents())
54 ->RunAction(extension, false);
55 EXPECT_TRUE(catcher.GetNextResult()) << message_;
56 }
57
41 // Granting to the extension should give it access to page.html. 58 // Granting to the extension should give it access to page.html.
42 { 59 {
43 ResultCatcher catcher; 60 ResultCatcher catcher;
44 ExtensionActionRunner::GetForWebContents( 61 ExtensionActionRunner::GetForWebContents(
45 browser()->tab_strip_model()->GetActiveWebContents()) 62 browser()->tab_strip_model()->GetActiveWebContents())
46 ->RunAction(extension, true); 63 ->RunAction(extension, true);
47 EXPECT_TRUE(catcher.GetNextResult()) << message_; 64 EXPECT_TRUE(catcher.GetNextResult()) << message_;
48 } 65 }
49 66
67 #if defined(OS_CHROMEOS)
68 // For the third pass grant the activeTab permission and do it in a public
69 // session. URL should be scrubbed down to origin.
70 {
71 // Setup state.
72 chromeos::ScopedTestPublicSessionLoginState login_state;
73 auto delegate = base::MakeUnique<ExtensionTabUtilDelegateChromeOS>();
74 ExtensionTabUtil::SetPlatformDelegate(delegate.get());
75
76 ExtensionTestMessageListener listener(false);
77 ResultCatcher catcher;
78 ExtensionActionRunner::GetForWebContents(
79 browser()->tab_strip_model()->GetActiveWebContents())
80 ->RunAction(extension, true);
81 EXPECT_TRUE(catcher.GetNextResult()) << message_;
82 EXPECT_EQ(GURL(listener.message()).GetOrigin().spec(), listener.message());
83
84 // Clean up.
85 ExtensionTabUtil::SetPlatformDelegate(nullptr);
86 }
87 #endif
88
50 // Changing page should go back to it not having access. 89 // Changing page should go back to it not having access.
51 { 90 {
52 ResultCatcher catcher; 91 ResultCatcher catcher;
53 ui_test_utils::NavigateToURL( 92 ui_test_utils::NavigateToURL(
54 browser(), 93 browser(),
55 embedded_test_server()->GetURL( 94 embedded_test_server()->GetURL(
56 "/extensions/api_test/active_tab/final_page.html")); 95 "/extensions/api_test/active_tab/final_page.html"));
57 EXPECT_TRUE(catcher.GetNextResult()) << message_; 96 EXPECT_TRUE(catcher.GetNextResult()) << message_;
58 } 97 }
59 } 98 }
60 99
61 } // namespace 100 } // namespace
62 } // namespace extensions 101 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/active_tab/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698