Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: ios/chrome/browser/web/form_resubmission_tab_helper_unittest.mm

Issue 2642463002: Implemented FormResubmissionTabHelper. (Closed)
Patch Set: Moved FormResubmissionTabHelper::CreateForWebState to init Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/web/form_resubmission_tab_helper.h"
6
7 #import <UIKit/UIKit.h>
8
9 #include "base/bind.h"
10 #include "base/mac/foundation_util.h"
11 #include "base/test/ios/wait_util.h"
12 #include "components/strings/grit/components_strings.h"
13 #include "ios/chrome/browser/ui/ui_util.h"
14 #import "ios/chrome/test/scoped_key_window.h"
15 #import "ios/web/public/test/fakes/test_web_state.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h"
18 #include "ui/base/l10n/l10n_util.h"
19
20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support."
22 #endif
23
24 namespace {
25 // Test location passed to PresentFormResubmissionDialog.
26 const CGFloat kDialogHLocation = 10;
27 const CGFloat kDialogVLocation = 20;
28
29 // No-op callback for PresentFormResubmissionDialog.
30 void IgnoreBool(bool) {}
31 } // namespace
32
33 // Test fixture for FormResubmissionTabHelper class.
34 class FormResubmissionTabHelperTest : public PlatformTest {
35 protected:
36 FormResubmissionTabHelperTest()
37 : web_state_(new web::TestWebState()),
38 location_(CGPointMake(kDialogHLocation, kDialogVLocation)),
39 view_controller_([[UIViewController alloc] init]) {
40 UIView* view = [[UIView alloc] initWithFrame:view_controller_.view.bounds];
41 [view_controller_.view addSubview:view];
42 [scoped_key_window_.Get() setRootViewController:view_controller_];
43
44 web_state_->SetView(view);
45 web_state_->SetWebUsageEnabled(true);
46
47 FormResubmissionTabHelper::CreateForWebState(web_state_.get());
48 }
49
50 // Presents form resubmission dialog using FormResubmissionTabHelperTest.
51 void PresentDialog() {
52 ASSERT_FALSE(GetAlertController());
53 auto helper = FormResubmissionTabHelper::FromWebState(web_state_.get());
54 helper->PresentFormResubmissionDialog(location_, base::Bind(&IgnoreBool));
55 ASSERT_TRUE(GetAlertController());
56 }
57
58 // Return presented view controller as UIAlertController.
59 UIAlertController* GetAlertController() const {
60 return base::mac::ObjCCastStrict<UIAlertController>(
61 view_controller_.presentedViewController);
62 }
63
64 protected:
65 std::unique_ptr<web::TestWebState> web_state_;
66
67 private:
68 CGPoint location_;
69 ScopedKeyWindow scoped_key_window_;
70 UIViewController* view_controller_;
71 };
72
73 // Tests presented Form Resubmission dialog.
74 TEST_F(FormResubmissionTabHelperTest, Preseting) {
75 PresentDialog();
76 EXPECT_FALSE(GetAlertController().title);
77 EXPECT_TRUE([GetAlertController().message
78 containsString:l10n_util::GetNSString(IDS_HTTP_POST_WARNING_TITLE)]);
79 EXPECT_TRUE([GetAlertController().message
80 containsString:l10n_util::GetNSString(IDS_HTTP_POST_WARNING)]);
81 if (IsIPadIdiom()) {
82 UIPopoverPresentationController* popover_presentation_controller =
83 GetAlertController().popoverPresentationController;
84 CGRect source_rect = popover_presentation_controller.sourceRect;
85 EXPECT_EQ(kDialogHLocation, CGRectGetMinX(source_rect));
86 EXPECT_EQ(kDialogVLocation, CGRectGetMinY(source_rect));
87 }
88 }
89
90 // Tests that dialog is dismissed when WebState is destroyed.
91 TEST_F(FormResubmissionTabHelperTest, DismissingOnWebViewDestruction) {
92 PresentDialog();
93 web_state_.reset();
94 base::test::ios::WaitUntilCondition(^{
95 return GetAlertController() != nil;
96 });
97 }
98
99 // Tests that dialog is dismissed after provisional navigation has started.
100 TEST_F(FormResubmissionTabHelperTest, DismissingOnNavigationStart) {
101 PresentDialog();
102 web_state_->OnProvisionalNavigationStarted(GURL());
103 base::test::ios::WaitUntilCondition(^{
104 return GetAlertController() != nil;
105 });
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698