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

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

Issue 2731443003: Removed CRWWebController dependency from NativeAppNavigationController. (Closed)
Patch Set: Added missing import Created 3 years, 9 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
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/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/user_metrics.h" 10 #include "base/metrics/user_metrics.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
11 #import "ios/chrome/browser/installation_notifier.h" 13 #import "ios/chrome/browser/installation_notifier.h"
12 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" 14 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h"
13 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller .h" 15 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller .h"
14 #import "ios/chrome/browser/web/chrome_web_test.h" 16 #import "ios/chrome/browser/web/chrome_web_test.h"
15 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_provider.h" 17 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_provider.h"
16 #import "ios/public/provider/chrome/browser/native_app_launcher/fake_native_app_ metadata.h" 18 #import "ios/public/provider/chrome/browser/native_app_launcher/fake_native_app_ metadata.h"
17 #import "ios/public/provider/chrome/browser/native_app_launcher/fake_native_app_ whitelist_manager.h" 19 #import "ios/public/provider/chrome/browser/native_app_launcher/fake_native_app_ whitelist_manager.h"
18 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" 20 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h"
21 #import "testing/gtest_mac.h"
19 22
20 @interface NativeAppNavigationController (Testing) 23 @interface NativeAppNavigationController (Testing)
21 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type 24 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type
22 onLinkNavigation:(BOOL)isLinkNavigation; 25 onLinkNavigation:(BOOL)isLinkNavigation;
23 - (NSMutableSet*)appsPossiblyBeingInstalled; 26 - (NSMutableSet*)appsPossiblyBeingInstalled;
24 - (void)removeAppFromNotification:(NSNotification*)notification; 27 - (void)removeAppFromNotification:(NSNotification*)notification;
25 @end 28 @end
26 29
27 namespace { 30 namespace {
28 31
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 113
111 SetExpectedActionName("MobileGALOpenPolicyInfoBar"); 114 SetExpectedActionName("MobileGALOpenPolicyInfoBar");
112 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER 115 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER
113 onLinkNavigation:YES]; 116 onLinkNavigation:YES];
114 ExpectHandlerCalledAndReset(1); 117 ExpectHandlerCalledAndReset(1);
115 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER 118 [controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER
116 onLinkNavigation:NO]; 119 onLinkNavigation:NO];
117 ExpectHandlerCalledAndReset(1); 120 ExpectHandlerCalledAndReset(1);
118 } 121 }
119 122
123 // Tests presenting NativeAppInfoBar after page is loaded.
124 TEST_F(NativeAppNavigationControllerTest, NativeAppInfoBar) {
125 SetExpectedActionName("MobileGALInstallInfoBarDirectNavigation");
126 InfoBarManagerImpl::CreateForWebState(web_state());
127
128 // Set up fake metadata.
129 FakeNativeAppWhitelistManager* fakeManager =
130 [[[FakeNativeAppWhitelistManager alloc] init] autorelease];
131 IOSChromeScopedTestingChromeBrowserProvider provider(
132 base::MakeUnique<FakeChromeBrowserProvider>(fakeManager));
133 FakeNativeAppMetadata* metadata =
134 [[[FakeNativeAppMetadata alloc] init] autorelease];
135 fakeManager.metadata = metadata;
136 metadata.appName = @"App";
137 metadata.appId = @"App-ID";
138
139 // Load the page to trigger infobar presentation.
140 LoadHtml(@"<html><body></body></html>", GURL("http://test.com"));
141
142 // Verify that infobar was presented
143 auto* infobar_manager = InfoBarManagerImpl::FromWebState(web_state());
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
149 // Verify infobar appearance.
150 EXPECT_EQ("Open this page in the App app?",
151 base::UTF16ToUTF8(delegate->GetInstallText()));
152 EXPECT_EQ("Open this page in the App app?",
153 base::UTF16ToUTF8(delegate->GetLaunchText()));
154 EXPECT_EQ("Open in App", base::UTF16ToUTF8(delegate->GetOpenPolicyText()));
155 EXPECT_EQ("Just once", base::UTF16ToUTF8(delegate->GetOpenOnceText()));
156 EXPECT_EQ("Always", base::UTF16ToUTF8(delegate->GetOpenAlwaysText()));
157 EXPECT_NSEQ(@"App-ID", delegate->GetAppId());
158 }
159
120 TEST_F(NativeAppNavigationControllerTest, 160 TEST_F(NativeAppNavigationControllerTest,
121 TestRemovingAppFromListAfterInstallation) { 161 TestRemovingAppFromListAfterInstallation) {
122 NSString* const kMapsAppName = @"Maps"; 162 NSString* const kMapsAppName = @"Maps";
123 NSString* const kMapsAppId = @"1"; 163 NSString* const kMapsAppId = @"1";
124 NSString* const kYoutubeAppName = @"Youtube"; 164 NSString* const kYoutubeAppName = @"Youtube";
125 NSString* const kYoutubeAppId = @"2"; 165 NSString* const kYoutubeAppId = @"2";
126 166
127 base::scoped_nsobject<InstallationNotifier> installationNotifier( 167 base::scoped_nsobject<InstallationNotifier> installationNotifier(
128 [[InstallationNotifier alloc] init]); 168 [[InstallationNotifier alloc] init]);
129 169
(...skipping 30 matching lines...) Expand all
160 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 2); 200 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 2);
161 [fakeManager setAppScheme:kMapsAppName]; 201 [fakeManager setAppScheme:kMapsAppName];
162 [controller_ removeAppFromNotification:notificationMaps]; 202 [controller_ removeAppFromNotification:notificationMaps];
163 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1); 203 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1);
164 [fakeManager setAppScheme:kYoutubeAppName]; 204 [fakeManager setAppScheme:kYoutubeAppName];
165 [controller_ removeAppFromNotification:notificationYouTube]; 205 [controller_ removeAppFromNotification:notificationYouTube];
166 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0); 206 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0);
167 } 207 }
168 208
169 } // namespace 209 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/native_app_launcher/native_app_navigation_controller.mm ('k') | ios/chrome/browser/tabs/tab.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698