summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/extension_apitest.cc16
-rw-r--r--chrome/browser/extensions/extension_apitest.h6
-rw-r--r--chrome/browser/extensions/extension_incognito_apitest.cc9
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc9
-rw-r--r--chrome/test/data/extensions/api_test/incognito/enumerate_tabs/background.html9
-rw-r--r--chrome/test/data/extensions/api_test/incognito/enumerate_tabs/manifest.json7
6 files changed, 48 insertions, 8 deletions
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc
index 3ebbeed..f5a5173 100644
--- a/chrome/browser/extensions/extension_apitest.cc
+++ b/chrome/browser/extensions/extension_apitest.cc
@@ -78,13 +78,17 @@ void ExtensionApiTest::ResultCatcher::Observe(
}
bool ExtensionApiTest::RunExtensionTest(const char* extension_name) {
- return RunExtensionTestImpl(extension_name, "");
+ return RunExtensionTestImpl(extension_name, "", false);
+}
+
+bool ExtensionApiTest::RunExtensionTestIncognito(const char* extension_name) {
+ return RunExtensionTestImpl(extension_name, "", true);
}
bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name,
const std::string& page_url) {
DCHECK(!page_url.empty()) << "Argument page_url is required.";
- return RunExtensionTestImpl(extension_name, page_url);
+ return RunExtensionTestImpl(extension_name, page_url, false);
}
bool ExtensionApiTest::RunPageTest(const std::string& page_url) {
@@ -94,7 +98,8 @@ bool ExtensionApiTest::RunPageTest(const std::string& page_url) {
// Load |extension_name| extension and/or |page_url| and wait for
// PASSED or FAILED notification.
bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
- const std::string& page_url) {
+ const std::string& page_url,
+ bool enable_incognito) {
ResultCatcher catcher;
DCHECK(!std::string(extension_name).empty() || !page_url.empty()) <<
"extension_name and page_url cannot both be empty";
@@ -102,7 +107,10 @@ bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
if (!std::string(extension_name).empty()) {
LOG(INFO) << "Loading Extension: " << extension_name;
- if (!LoadExtension(test_data_dir_.AppendASCII(extension_name))) {
+ bool loaded = enable_incognito ?
+ LoadExtensionIncognito(test_data_dir_.AppendASCII(extension_name)) :
+ LoadExtension(test_data_dir_.AppendASCII(extension_name));
+ if (!loaded) {
message_ = "Failed to load extension.";
return false;
}
diff --git a/chrome/browser/extensions/extension_apitest.h b/chrome/browser/extensions/extension_apitest.h
index 638131c..194750d 100644
--- a/chrome/browser/extensions/extension_apitest.h
+++ b/chrome/browser/extensions/extension_apitest.h
@@ -69,6 +69,9 @@ class ExtensionApiTest : public ExtensionBrowserTest {
// |extension_name| is a directory in "test/data/extensions/api_test".
bool RunExtensionTest(const char* extension_name);
+ // Same as RunExtensionTest, but enables the extension for incognito mode.
+ bool RunExtensionTestIncognito(const char* extension_name);
+
// If not empty, Load |extension_name|, load |page_url| and wait for pass /
// fail notification from the extension API on the page. Note that if
// |page_url| is not a valid url, it will be treated as a resource within
@@ -93,7 +96,8 @@ class ExtensionApiTest : public ExtensionBrowserTest {
private:
bool RunExtensionTestImpl(const char* extension_name,
- const std::string& test_page);
+ const std::string& test_page,
+ bool enable_incogntio);
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_APITEST_H_
diff --git a/chrome/browser/extensions/extension_incognito_apitest.cc b/chrome/browser/extensions/extension_incognito_apitest.cc
index 64a3c67..c287fda 100644
--- a/chrome/browser/extensions/extension_incognito_apitest.cc
+++ b/chrome/browser/extensions/extension_incognito_apitest.cc
@@ -78,6 +78,15 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, IncognitoYesScript) {
EXPECT_TRUE(result);
}
+// Tests that an extension which is enabled for incognito mode doesn't
+// accidentially create and incognito profile.
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DontCreateIncognitoProfile) {
+ ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
+ ASSERT_TRUE(
+ RunExtensionTestIncognito("incognito/enumerate_tabs")) << message_;
+ ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile());
+}
+
// Tests that the APIs in an incognito-enabled extension work properly.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) {
host_resolver()->AddRule("*", "127.0.0.1");
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 9b66cd0..6cf9c42 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -190,7 +190,8 @@ bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile,
TabStripModel* target_tab_strip;
TabContents* target_contents;
Profile* incognito_profile =
- include_incognito ? profile->GetOffTheRecordProfile() : NULL;
+ include_incognito && profile->HasOffTheRecordProfile() ?
+ profile->GetOffTheRecordProfile() : NULL;
for (BrowserList::const_iterator iter = BrowserList::begin();
iter != BrowserList::end(); ++iter) {
target_browser = *iter;
@@ -269,7 +270,8 @@ bool GetAllWindowsFunction::RunImpl() {
result_.reset(new ListValue());
Profile* incognito_profile =
- include_incognito() ? profile()->GetOffTheRecordProfile() : NULL;
+ include_incognito() && profile()->HasOffTheRecordProfile() ?
+ profile()->GetOffTheRecordProfile() : NULL;
for (BrowserList::const_iterator browser = BrowserList::begin();
browser != BrowserList::end(); ++browser) {
// Only examine browsers in the current profile that have windows.
@@ -1056,7 +1058,8 @@ static Browser* GetBrowserInProfileWithId(Profile* profile,
bool include_incognito,
std::string* error_message) {
Profile* incognito_profile =
- include_incognito ? profile->GetOffTheRecordProfile() : NULL;
+ include_incognito && profile->HasOffTheRecordProfile() ?
+ profile->GetOffTheRecordProfile() : NULL;
for (BrowserList::const_iterator browser = BrowserList::begin();
browser != BrowserList::end(); ++browser) {
if (((*browser)->profile() == profile ||
diff --git a/chrome/test/data/extensions/api_test/incognito/enumerate_tabs/background.html b/chrome/test/data/extensions/api_test/incognito/enumerate_tabs/background.html
new file mode 100644
index 0000000..c8777a7
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/incognito/enumerate_tabs/background.html
@@ -0,0 +1,9 @@
+<script>
+chrome.test.runTests([
+ function enumerateTabs() {
+ chrome.windows.getAll({"populate": true}, function (windows) {
+ chrome.test.succeed();
+ });
+ }
+]);
+</script>
diff --git a/chrome/test/data/extensions/api_test/incognito/enumerate_tabs/manifest.json b/chrome/test/data/extensions/api_test/incognito/enumerate_tabs/manifest.json
new file mode 100644
index 0000000..fc85e95
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/incognito/enumerate_tabs/manifest.json
@@ -0,0 +1,7 @@
+{
+ "name": "incognito apitest",
+ "version": "0.1",
+ "description": "test that an incognito extension can't accidentially create an OTR profile",
+ "background_page": "background.html",
+ "permissions": ["tabs"]
+}