summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-21 09:58:01 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-21 09:58:01 +0000
commita320e51df14cf5f2112783b8390fc77e3bf0c569 (patch)
tree8424e0fe1efe545fccc5e7b3f4b6d08e8341d366 /chrome/browser
parenta4949656364a4d4ad177eedfda6f4d4228f1155b (diff)
downloadchromium_src-a320e51df14cf5f2112783b8390fc77e3bf0c569.zip
chromium_src-a320e51df14cf5f2112783b8390fc77e3bf0c569.tar.gz
chromium_src-a320e51df14cf5f2112783b8390fc77e3bf0c569.tar.bz2
Do not create an incogntio profile as side effect when listing all tabs/windows.
BUG=55479 TEST=DontCreateIncognitoProfile Review URL: http://codereview.chromium.org/3412005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60039 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-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
4 files changed, 32 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 ||