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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/active_tab_apitest.cc
diff --git a/chrome/browser/extensions/active_tab_apitest.cc b/chrome/browser/extensions/active_tab_apitest.cc
index 24e860c4d904f91bb7db7382c5f07cdea489b798..7b265d540fd8b3c8ecb07f90323a724811c80f77 100644
--- a/chrome/browser/extensions/active_tab_apitest.cc
+++ b/chrome/browser/extensions/active_tab_apitest.cc
@@ -5,13 +5,20 @@
#include "base/logging.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "extensions/common/extension.h"
+#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/extensions/extension_tab_util_delegate_chromeos.h"
+#include "chromeos/login/scoped_test_public_session_login_state.h"
+#endif
+
namespace extensions {
namespace {
@@ -38,6 +45,16 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ActiveTab) {
EXPECT_TRUE(catcher.GetNextResult()) << message_;
}
+ // Do one pass of BrowserAction without granting activeTab permission,
+ // extension shouldn't have access to tab.url.
+ {
+ ResultCatcher catcher;
+ ExtensionActionRunner::GetForWebContents(
+ browser()->tab_strip_model()->GetActiveWebContents())
+ ->RunAction(extension, false);
+ EXPECT_TRUE(catcher.GetNextResult()) << message_;
+ }
+
// Granting to the extension should give it access to page.html.
{
ResultCatcher catcher;
@@ -47,6 +64,28 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ActiveTab) {
EXPECT_TRUE(catcher.GetNextResult()) << message_;
}
+#if defined(OS_CHROMEOS)
+ // For the third pass grant the activeTab permission and do it in a public
+ // session. URL should be scrubbed down to origin.
+ {
+ // Setup state.
+ chromeos::ScopedTestPublicSessionLoginState login_state;
+ auto delegate = base::MakeUnique<ExtensionTabUtilDelegateChromeOS>();
+ ExtensionTabUtil::SetPlatformDelegate(delegate.get());
+
+ ExtensionTestMessageListener listener(false);
+ ResultCatcher catcher;
+ ExtensionActionRunner::GetForWebContents(
+ browser()->tab_strip_model()->GetActiveWebContents())
+ ->RunAction(extension, true);
+ EXPECT_TRUE(catcher.GetNextResult()) << message_;
+ EXPECT_EQ(GURL(listener.message()).GetOrigin().spec(), listener.message());
+
+ // Clean up.
+ ExtensionTabUtil::SetPlatformDelegate(nullptr);
+ }
+#endif
+
// Changing page should go back to it not having access.
{
ResultCatcher catcher;
« 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