Index: chrome/browser/extensions/extension_messages_apitest.cc |
diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc |
index 9bee026d46a10953412df31f28efbc67b37d83eb..32fef9ae20b9198603f519a85717afeab261f48d 100644 |
--- a/chrome/browser/extensions/extension_messages_apitest.cc |
+++ b/chrome/browser/extensions/extension_messages_apitest.cc |
@@ -23,7 +23,9 @@ |
#include "build/build_config.h" |
#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/extensions/api/messaging/incognito_connectability.h" |
+#include "chrome/browser/extensions/chrome_extension_test_notification_observer.h" |
#include "chrome/browser/extensions/extension_apitest.h" |
+#include "chrome/browser/extensions/extension_util.h" |
#include "chrome/browser/extensions/test_extension_dir.h" |
#include "chrome/browser/infobars/infobar_service.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -783,22 +785,26 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
->GetActiveWebContents() |
->GetMainFrame(); |
- { |
- IncognitoConnectability::ScopedAlertTracker alert_tracker( |
- IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); |
- |
- // The alert doesn't show for extensions. |
- EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
- CanConnectAndSendMessagesToFrame( |
- incognito_frame, extension.get(), NULL)); |
- EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
- } |
- |
- // Allowing the extension in incognito mode will bypass the deny. |
- ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(extension->id(), true); |
- EXPECT_EQ( |
- OK, |
- CanConnectAndSendMessagesToFrame(incognito_frame, extension.get(), NULL)); |
+ IncognitoConnectability::ScopedAlertTracker alert_tracker( |
+ IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); |
+ |
+ // Extensions disabled in incognito mode are not loaded in an incognito |
+ // renderer. |
+ EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessagesToFrame( |
+ incognito_frame, extension.get(), NULL)); |
+ |
+ // Allowing the extension in incognito mode loads the extension in the |
+ // incognito renderer, allowing it to receive connections. |
+ ChromeExtensionTestNotificationObserver observer(incognito_browser); |
+ util::SetIsIncognitoEnabled(extension->id(), |
+ profile()->GetOffTheRecordProfile(), true); |
+ observer.WaitForExtensionLoad(); |
+ EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, |
+ extension.get(), NULL)); |
Devlin
2017/03/23 22:08:36
Subtle: when we reload the extension, the Extensio
Devlin
2017/03/23 22:08:37
prefer nullptr in new code
karandeepb
2017/04/04 03:44:15
Done.
karandeepb
2017/04/04 03:44:15
Done.
|
+ |
+ // No alert is shown for extensions which support being enabled in incognito |
+ // mode. |
+ EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
} |
// Tests connection from incognito tabs when the extension doesn't have an event |
@@ -958,22 +964,26 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
->GetActiveWebContents() |
->GetMainFrame(); |
- { |
- IncognitoConnectability::ScopedAlertTracker alert_tracker( |
- IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); |
- |
- // No alert is shown. |
- EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
- CanConnectAndSendMessagesToFrame( |
- incognito_frame, extension.get(), NULL)); |
- EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
- } |
- |
- // Allowing the extension in incognito mode is what allows connections. |
- ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(extension->id(), true); |
- EXPECT_EQ( |
- OK, |
- CanConnectAndSendMessagesToFrame(incognito_frame, extension.get(), NULL)); |
+ IncognitoConnectability::ScopedAlertTracker alert_tracker( |
+ IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); |
+ |
+ // Extensions disabled in incognito mode are not loaded in an incognito |
+ // renderer. |
+ EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessagesToFrame( |
+ incognito_frame, extension.get(), NULL)); |
+ |
+ // Allowing the extension in incognito mode loads the extension in the |
+ // incognito renderer, allowing it to receive connections. |
+ ChromeExtensionTestNotificationObserver observer(incognito_browser); |
+ util::SetIsIncognitoEnabled(extension->id(), |
+ profile()->GetOffTheRecordProfile(), true); |
+ observer.WaitForExtensionLoad(); |
+ EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, |
+ extension.get(), NULL)); |
Devlin
2017/03/23 22:08:37
(Same comment here)
karandeepb
2017/04/04 03:44:15
Done.
|
+ |
+ // No alert is shown for extensions which support being enabled in incognito |
+ // mode. |
+ EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
} |
// Tests a connection from an iframe within a tab which doesn't have |