| OLD | NEW |
| 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/message_loop/message_loop.h" | |
| 11 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| 12 #import "ios/chrome/browser/installation_notifier.h" | 11 #import "ios/chrome/browser/installation_notifier.h" |
| 13 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" | 12 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" |
| 14 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller
.h" | 13 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller
.h" |
| 14 #import "ios/chrome/browser/web/chrome_web_test.h" |
| 15 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_provider.h" | 15 #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" | 16 #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" | 17 #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" | 18 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" |
| 19 #include "ios/web/public/test/test_web_thread.h" | |
| 20 #include "net/url_request/url_request_test_util.h" | |
| 21 #include "testing/platform_test.h" | |
| 22 | 19 |
| 23 @interface NativeAppNavigationController (Testing) | 20 @interface NativeAppNavigationController (Testing) |
| 24 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type | 21 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type |
| 25 onLinkNavigation:(BOOL)isLinkNavigation; | 22 onLinkNavigation:(BOOL)isLinkNavigation; |
| 26 - (NSMutableSet*)appsPossiblyBeingInstalled; | 23 - (NSMutableSet*)appsPossiblyBeingInstalled; |
| 27 - (void)removeAppFromNotification:(NSNotification*)notification; | 24 - (void)removeAppFromNotification:(NSNotification*)notification; |
| 28 @end | 25 @end |
| 29 | 26 |
| 30 namespace { | 27 namespace { |
| 31 | 28 |
| 32 class FakeChromeBrowserProvider : public ios::TestChromeBrowserProvider { | 29 class FakeChromeBrowserProvider : public ios::TestChromeBrowserProvider { |
| 33 public: | 30 public: |
| 34 FakeChromeBrowserProvider(FakeNativeAppWhitelistManager* fake_manager) { | 31 FakeChromeBrowserProvider(FakeNativeAppWhitelistManager* fake_manager) { |
| 35 manager_.reset([fake_manager retain]); | 32 manager_.reset([fake_manager retain]); |
| 36 } | 33 } |
| 37 ~FakeChromeBrowserProvider() override {} | 34 ~FakeChromeBrowserProvider() override {} |
| 38 | 35 |
| 39 id<NativeAppWhitelistManager> GetNativeAppWhitelistManager() const override { | 36 id<NativeAppWhitelistManager> GetNativeAppWhitelistManager() const override { |
| 40 return manager_; | 37 return manager_; |
| 41 } | 38 } |
| 42 | 39 |
| 43 private: | 40 private: |
| 44 base::scoped_nsprotocol<id<NativeAppWhitelistManager>> manager_; | 41 base::scoped_nsprotocol<id<NativeAppWhitelistManager>> manager_; |
| 45 }; | 42 }; |
| 46 | 43 |
| 47 class NativeAppNavigationControllerTest : public PlatformTest { | 44 class NativeAppNavigationControllerTest : public ChromeWebTest { |
| 48 public: | |
| 49 NativeAppNavigationControllerTest() | |
| 50 : loop_(base::MessageLoop::TYPE_IO), | |
| 51 ui_thread_(web::WebThread::UI, &loop_) {} | |
| 52 | |
| 53 protected: | 45 protected: |
| 54 void SetUp() override { | 46 void SetUp() override { |
| 55 request_context_getter_ = | 47 ChromeWebTest::SetUp(); |
| 56 new net::TestURLRequestContextGetter(loop_.task_runner()); | |
| 57 controller_.reset([[NativeAppNavigationController alloc] | 48 controller_.reset([[NativeAppNavigationController alloc] |
| 58 initWithRequestContextGetter:request_context_getter_.get() | 49 initWithWebState:web_state() |
| 59 tab:nil]); | 50 requestContextGetter:GetBrowserState()->GetRequestContext() |
| 51 tab:nil]); |
| 60 | 52 |
| 61 action_callback_ = | 53 action_callback_ = |
| 62 base::Bind(&NativeAppNavigationControllerTest::OnUserAction, | 54 base::Bind(&NativeAppNavigationControllerTest::OnUserAction, |
| 63 base::Unretained(this)); | 55 base::Unretained(this)); |
| 64 base::AddActionCallback(action_callback_); | 56 base::AddActionCallback(action_callback_); |
| 65 | 57 |
| 66 handler_called_counter_ = 0; | 58 handler_called_counter_ = 0; |
| 67 } | 59 } |
| 68 | 60 |
| 69 void TearDown() override { base::RemoveActionCallback(action_callback_); } | 61 void TearDown() override { |
| 62 base::RemoveActionCallback(action_callback_); |
| 63 ChromeWebTest::TearDown(); |
| 64 } |
| 70 | 65 |
| 71 void SetExpectedActionName(const std::string& action_name) { | 66 void SetExpectedActionName(const std::string& action_name) { |
| 72 expected_action_name_.reset(new std::string(action_name)); | 67 expected_action_name_.reset(new std::string(action_name)); |
| 73 } | 68 } |
| 74 | 69 |
| 75 void OnUserAction(const std::string& action_name) { | 70 void OnUserAction(const std::string& action_name) { |
| 76 EXPECT_EQ(*expected_action_name_, action_name); | 71 EXPECT_EQ(*expected_action_name_, action_name); |
| 77 handler_called_counter_++; | 72 handler_called_counter_++; |
| 78 } | 73 } |
| 79 | 74 |
| 80 void ExpectHandlerCalledAndReset(int number_of_calls) { | 75 void ExpectHandlerCalledAndReset(int number_of_calls) { |
| 81 EXPECT_EQ(number_of_calls, handler_called_counter_); | 76 EXPECT_EQ(number_of_calls, handler_called_counter_); |
| 82 handler_called_counter_ = 0; | 77 handler_called_counter_ = 0; |
| 83 } | 78 } |
| 84 | 79 |
| 85 base::MessageLoop loop_; | |
| 86 web::TestWebThread ui_thread_; | |
| 87 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
| 88 base::scoped_nsobject<NativeAppNavigationController> controller_; | 80 base::scoped_nsobject<NativeAppNavigationController> controller_; |
| 89 | 81 |
| 90 // The callback to invoke when an action is recorded. | 82 // The callback to invoke when an action is recorded. |
| 91 base::ActionCallback action_callback_; | 83 base::ActionCallback action_callback_; |
| 92 std::unique_ptr<std::string> expected_action_name_; | 84 std::unique_ptr<std::string> expected_action_name_; |
| 93 int handler_called_counter_; | 85 int handler_called_counter_; |
| 94 }; | 86 }; |
| 95 | 87 |
| 96 TEST_F(NativeAppNavigationControllerTest, TestConstructor) { | 88 TEST_F(NativeAppNavigationControllerTest, TestConstructor) { |
| 97 EXPECT_TRUE(controller_); | 89 EXPECT_TRUE(controller_); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 2); | 160 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 2); |
| 169 [fakeManager setAppScheme:kMapsAppName]; | 161 [fakeManager setAppScheme:kMapsAppName]; |
| 170 [controller_ removeAppFromNotification:notificationMaps]; | 162 [controller_ removeAppFromNotification:notificationMaps]; |
| 171 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1); | 163 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1); |
| 172 [fakeManager setAppScheme:kYoutubeAppName]; | 164 [fakeManager setAppScheme:kYoutubeAppName]; |
| 173 [controller_ removeAppFromNotification:notificationYouTube]; | 165 [controller_ removeAppFromNotification:notificationYouTube]; |
| 174 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0); | 166 DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0); |
| 175 } | 167 } |
| 176 | 168 |
| 177 } // namespace | 169 } // namespace |
| OLD | NEW |