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

Side by Side Diff: ios/chrome/browser/native_app_launcher/native_app_navigation_controller_unittest.mm

Issue 2916473002: [ObjC ARC] Converts ios/web:web to ARC. (Closed)
Patch Set: Adoption of NS_VALID_UNTIL_END_OF_SCOPE Created 3 years, 6 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
« no previous file with comments | « no previous file | ios/web/BUILD.gn » ('j') | ios/web/test/web_int_test.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/user_metrics.h" 9 #include "base/metrics/user_metrics.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 action_callback_ = 57 action_callback_ =
58 base::Bind(&NativeAppNavigationControllerTest::OnUserAction, 58 base::Bind(&NativeAppNavigationControllerTest::OnUserAction,
59 base::Unretained(this)); 59 base::Unretained(this));
60 base::AddActionCallback(action_callback_); 60 base::AddActionCallback(action_callback_);
61 61
62 handler_called_counter_ = 0; 62 handler_called_counter_ = 0;
63 } 63 }
64 64
65 void TearDown() override { 65 void TearDown() override {
66 base::RemoveActionCallback(action_callback_); 66 base::RemoveActionCallback(action_callback_);
67 controller_ = nil;
67 ChromeWebTest::TearDown(); 68 ChromeWebTest::TearDown();
68 } 69 }
69 70
70 void SetExpectedActionName(const std::string& action_name) { 71 void SetExpectedActionName(const std::string& action_name) {
71 expected_action_name_.reset(new std::string(action_name)); 72 expected_action_name_.reset(new std::string(action_name));
72 } 73 }
73 74
74 void OnUserAction(const std::string& action_name) { 75 void OnUserAction(const std::string& action_name) {
75 EXPECT_EQ(*expected_action_name_, action_name); 76 EXPECT_EQ(*expected_action_name_, action_name);
76 handler_called_counter_++; 77 handler_called_counter_++;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER 117 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER
117 onLinkNavigation:YES]; 118 onLinkNavigation:YES];
118 ExpectHandlerCalledAndReset(1); 119 ExpectHandlerCalledAndReset(1);
119 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER 120 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER
120 onLinkNavigation:NO]; 121 onLinkNavigation:NO];
121 ExpectHandlerCalledAndReset(1); 122 ExpectHandlerCalledAndReset(1);
122 } 123 }
123 124
124 // Tests presenting NativeAppInfoBar after page is loaded. 125 // Tests presenting NativeAppInfoBar after page is loaded.
125 TEST_F(NativeAppNavigationControllerTest, NativeAppInfoBar) { 126 TEST_F(NativeAppNavigationControllerTest, NativeAppInfoBar) {
126 SetExpectedActionName("MobileGALInstallInfoBarDirectNavigation"); 127 // An autorelease pool is used here to make sure that objects autoreleased
127 InfoBarManagerImpl::CreateForWebState(web_state()); 128 // during the running of this test are released at the end of the test, and
129 // not caught by the root pool. This is important as some DCHECKs run when
130 // objects like NativeAppNavigationController are released, and they expect
131 // that the web thread state is still coherent at this time (i.e. the
132 // expected web threads (UI, DB, etc.) are still running and valid. If left
133 // to the root autoreleasepool there is no guarantee that objects will be
134 // released in the correct order, causing test flake or failures.
128 135
129 // Set up fake metadata. 136 @autoreleasepool {
Eugene But (OOO till 7-30) 2017/06/02 23:18:37 How about using ScopedNSAutoreleasePool? This will
PL 2017/06/05 23:26:18 I think the @autoreleasepool is supposed to be mor
130 FakeNativeAppWhitelistManager* fakeManager = 137 SetExpectedActionName("MobileGALInstallInfoBarDirectNavigation");
131 [[FakeNativeAppWhitelistManager alloc] init]; 138 InfoBarManagerImpl::CreateForWebState(web_state());
132 IOSChromeScopedTestingChromeBrowserProvider provider(
133 base::MakeUnique<FakeChromeBrowserProvider>(fakeManager));
134 FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init];
135 fakeManager.metadata = metadata;
136 metadata.appName = @"App";
137 metadata.appId = @"App-ID";
138 139
139 // Load the page to trigger infobar presentation. 140 // Set up fake metadata.
140 LoadHtml(@"<html><body></body></html>", GURL("http://test.com")); 141 FakeNativeAppWhitelistManager* fakeManager =
142 [[FakeNativeAppWhitelistManager alloc] init];
143 IOSChromeScopedTestingChromeBrowserProvider provider(
144 base::MakeUnique<FakeChromeBrowserProvider>(fakeManager));
145 FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init];
146 fakeManager.metadata = metadata;
147 metadata.appName = @"App";
148 metadata.appId = @"App-ID";
141 149
142 // Verify that infobar was presented 150 // Load the page to trigger infobar presentation.
143 auto* infobar_manager = InfoBarManagerImpl::FromWebState(web_state()); 151 LoadHtml(@"<html><body></body></html>", GURL("http://test.com"));
144 ASSERT_EQ(1U, infobar_manager->infobar_count());
145 infobars::InfoBar* infobar = infobar_manager->infobar_at(0);
146 auto* delegate = infobar->delegate()->AsNativeAppInfoBarDelegate();
147 ASSERT_TRUE(delegate);
148 152
149 // Verify infobar appearance. 153 // Verify that infobar was presented
150 EXPECT_EQ("Open this page in the App app?", 154 auto* infobar_manager = InfoBarManagerImpl::FromWebState(web_state());
151 base::UTF16ToUTF8(delegate->GetInstallText())); 155 ASSERT_EQ(1U, infobar_manager->infobar_count());
152 EXPECT_EQ("Open this page in the App app?", 156 infobars::InfoBar* infobar = infobar_manager->infobar_at(0);
153 base::UTF16ToUTF8(delegate->GetLaunchText())); 157 auto* delegate = infobar->delegate()->AsNativeAppInfoBarDelegate();
154 EXPECT_EQ("Open in App", base::UTF16ToUTF8(delegate->GetOpenPolicyText())); 158 ASSERT_TRUE(delegate);
155 EXPECT_EQ("Just once", base::UTF16ToUTF8(delegate->GetOpenOnceText())); 159
156 EXPECT_EQ("Always", base::UTF16ToUTF8(delegate->GetOpenAlwaysText())); 160 // Verify infobar appearance.
157 EXPECT_NSEQ(@"App-ID", delegate->GetAppId()); 161 EXPECT_EQ("Open this page in the App app?",
162 base::UTF16ToUTF8(delegate->GetInstallText()));
163 EXPECT_EQ("Open this page in the App app?",
164 base::UTF16ToUTF8(delegate->GetLaunchText()));
165 EXPECT_EQ("Open in App", base::UTF16ToUTF8(delegate->GetOpenPolicyText()));
166 EXPECT_EQ("Just once", base::UTF16ToUTF8(delegate->GetOpenOnceText()));
167 EXPECT_EQ("Always", base::UTF16ToUTF8(delegate->GetOpenAlwaysText()));
168 EXPECT_NSEQ(@"App-ID", delegate->GetAppId());
169 }
158 } 170 }
159 171
160 TEST_F(NativeAppNavigationControllerTest, 172 TEST_F(NativeAppNavigationControllerTest,
161 TestRemovingAppFromListAfterInstallation) { 173 TestRemovingAppFromListAfterInstallation) {
162 NSString* const kMapsAppName = @"Maps"; 174 NSString* const kMapsAppName = @"Maps";
163 NSString* const kMapsAppId = @"1"; 175 NSString* const kMapsAppId = @"1";
164 NSString* const kYoutubeAppName = @"Youtube"; 176 NSString* const kYoutubeAppName = @"Youtube";
165 NSString* const kYoutubeAppId = @"2"; 177 NSString* const kYoutubeAppId = @"2";
166 178
167 InstallationNotifier* installationNotifier = 179 InstallationNotifier* installationNotifier =
(...skipping 30 matching lines...) Expand all
198 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 2); 210 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 2);
199 [fakeManager setAppScheme:kMapsAppName]; 211 [fakeManager setAppScheme:kMapsAppName];
200 [controller_ removeAppFromNotification:notificationMaps]; 212 [controller_ removeAppFromNotification:notificationMaps];
201 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1); 213 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1);
202 [fakeManager setAppScheme:kYoutubeAppName]; 214 [fakeManager setAppScheme:kYoutubeAppName];
203 [controller_ removeAppFromNotification:notificationYouTube]; 215 [controller_ removeAppFromNotification:notificationYouTube];
204 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0); 216 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0);
205 } 217 }
206 218
207 } // namespace 219 } // namespace
OLDNEW
« no previous file with comments | « no previous file | ios/web/BUILD.gn » ('j') | ios/web/test/web_int_test.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698