Commit 1e2a1afa authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Add incognito mode tests for Extensions Tabs API.

Tests are added to Extensions Tabs API to ensure extensions cannot
create or query the tabs in incognito mode when they are not enabled
to run there.

Bug: 862075
Change-Id: I6081b4cc432c82d147a65f30311af0708efe03f9
Reviewed-on: https://chromium-review.googlesource.com/1158368
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582514}
parent 1e567fdd
......@@ -4,7 +4,9 @@
#include "chrome/browser/extensions/extension_apitest.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
......@@ -287,6 +289,28 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabOpenerCraziness) {
ASSERT_TRUE(RunExtensionTest("tabs/tab_opener_id"));
}
class IncognitoExtensionApiTabTest : public ExtensionApiTabTest,
public testing::WithParamInterface<bool> {
};
IN_PROC_BROWSER_TEST_P(IncognitoExtensionApiTabTest, Tabs) {
bool is_incognito_enabled = GetParam();
Browser* incognito_browser =
OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
std::string args = base::StringPrintf(
R"({"isIncognito": %s, "windowId": %d})",
is_incognito_enabled ? "true" : "false",
extensions::ExtensionTabUtil::GetWindowId(incognito_browser));
EXPECT_TRUE(RunExtensionSubtestWithArgAndFlags(
"tabs/basics", "incognito.html", args.data(),
is_incognito_enabled ? extensions::ExtensionApiTest::kFlagEnableIncognito
: extensions::ExtensionApiTest::kFlagNone))
<< message_;
}
INSTANTIATE_TEST_CASE_P(, IncognitoExtensionApiTabTest, testing::Bool());
// Adding a new test? Awesome. But API tests are the old hotness. The new
// hotness is extension_function_test_utils. See tabs_test.cc for an example.
// We are trying to phase out many uses of API tests as they tend to be flaky.
<!--
* Copyright 2018 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<script src="tabs_util.js"></script>
<script src="incognito.js"></script>
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.test.getConfig(function(config) {
let args = JSON.parse(config.customArg);
chrome.test.runTests([
function queryTabs() {
chrome.tabs.query(
{windowId: args.windowId},
pass(function(tabs) {
assertEq(tabs.length, args.isIncognito ? 1 : 0);
})
);
},
function createTab() {
chrome.tabs.create(
{windowId: args.windowId},
args.isIncognito ?
pass(function(tab) {assertTrue(tab.incognito);}) :
fail('No window with id: ' + args.windowId + ".")
);
},
]);
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment