Chromium Code Reviews| Index: ios/chrome/browser/ui/dialogs/dialog_presenter_unittest.mm |
| diff --git a/ios/chrome/browser/ui/dialogs/dialog_presenter_unittest.mm b/ios/chrome/browser/ui/dialogs/dialog_presenter_unittest.mm |
| index 2bd6df4fd3fc499072b401d0e03915c8e8f71ccf..77ad1e76df752bdd47032024fa66d148fec2a7f9 100644 |
| --- a/ios/chrome/browser/ui/dialogs/dialog_presenter_unittest.mm |
| +++ b/ios/chrome/browser/ui/dialogs/dialog_presenter_unittest.mm |
| @@ -5,12 +5,14 @@ |
| #import "ios/chrome/browser/ui/dialogs/dialog_presenter.h" |
| #include "base/time/time.h" |
| +#include "components/strings/grit/components_strings.h" |
| #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" |
| #import "ios/web/public/test/fakes/test_web_state.h" |
| #include "ios/web/public/web_state/web_state_observer.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "testing/gtest_mac.h" |
| #include "testing/platform_test.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #include "url/gurl.h" |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| @@ -97,6 +99,43 @@ TEST_F(DialogPresenterTest, SimpleTest) { |
| EXPECT_EQ(&webState, delegate().presentedWebStates.front()); |
| } |
| +// Test that javascript dialogs are presented with a different title when they |
| +// are presented from a URL with a different origin to the webstate origin. |
| +TEST_F(DialogPresenterTest, IFrameTest) { |
| + DialogPresenterTestWebState web_state; |
| + GURL foo_url = GURL("http://foo.com"); |
| + GURL bar_url = GURL("http://bar.com"); |
| + |
| + web_state.SetCurrentURL(foo_url); |
| + [presenter() runJavaScriptAlertPanelWithMessage:@"" |
| + requestURL:foo_url |
| + webState:&web_state |
| + completionHandler:nil]; |
| + |
| + // Ensure alerts from the same domain have a title. |
| + NSString* same_origin_title = |
| + [presenter() presentedDialogCoordinator].alertController.title; |
| + EXPECT_FALSE([same_origin_title length] == 0); |
|
Eugene But (OOO till 7-30)
2017/06/29 20:35:10
Is it possible to check the title in this test? Te
PL
2017/06/29 21:09:04
Done!
|
| + |
| + [presenter() cancelAllDialogs]; |
| + |
| + // Ensure that alerts from an embedded iframe with a different domain have |
| + // a title and it's different to the same-origin title. |
| + web_state.SetCurrentURL(bar_url); |
| + [presenter() runJavaScriptAlertPanelWithMessage:@"" |
| + requestURL:foo_url |
| + webState:&web_state |
| + completionHandler:nil]; |
| + NSString* different_origin_title = |
| + [presenter() presentedDialogCoordinator].alertController.title; |
| + EXPECT_FALSE([different_origin_title length] == 0); |
|
Eugene But (OOO till 7-30)
2017/06/29 20:35:10
Instead of this and the next "EXPECT" call you can
PL
2017/06/29 21:09:04
Done!
|
| + EXPECT_TRUE([different_origin_title |
| + isEqualToString: |
| + l10n_util::GetNSString( |
| + IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME)]); |
| + EXPECT_FALSE([same_origin_title isEqualToString:different_origin_title]); |
|
Eugene But (OOO till 7-30)
2017/06/29 20:35:10
Is it possible to drop this "EXPECT" in favor of c
PL
2017/06/29 21:09:04
Done! You're right, this one won't be needed any m
|
| +} |
| + |
| // Tests that multiple JavaScript dialogs are queued |
| TEST_F(DialogPresenterTest, QueueTest) { |
| // Tests that the dialog for |webState1| has been shown. |