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

Unified Diff: ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm

Issue 2742173002: Removed use of CRWSessionController from NativeAppNavigationUtilsTest. (Closed)
Patch Set: removed unneeded includes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/native_app_launcher/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm
diff --git a/ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm b/ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm
index e37c3331401de20cb6c424665766abcf40eb5644..74f8ca063048a2f1e0cbeebc32004432e85da1a8 100644
--- a/ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm
+++ b/ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm
@@ -4,47 +4,62 @@
#include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h"
-#import "ios/web/navigation/crw_session_controller.h"
-#import "ios/web/navigation/navigation_manager_impl.h"
-#include "ios/web/public/referrer.h"
-#include "ios/web/public/test/web_test.h"
-#import "ios/web/web_state/web_state_impl.h"
+#include "base/memory/ptr_util.h"
+#import "ios/web/public/navigation_item.h"
+#import "ios/web/public/navigation_item_list.h"
Eugene But (OOO till 7-30) 2017/03/13 21:05:40 nit: s/import/include
pkl (ping after 24h if needed) 2017/03/14 02:12:48 Acknowledged.
+#import "ios/web/public/test/fakes/test_navigation_manager.h"
+#import "ios/web/public/test/fakes/test_web_state.h"
+#include "testing/platform_test.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"
-namespace {
+// Overrides underlying NavigationManager methods used by IsLinkNavigation().
+class TestNavigationManager : public web::TestNavigationManager {
+ public:
+ int GetCurrentItemIndex() const override {
+ // For testing, just return the last item. Returns -1 if |items_| is empty.
+ return items_.size() - 1;
+ }
-class NativeAppNavigationUtilsTest : public web::WebTest {
- protected:
- void SetUp() override {
- web::WebTest::SetUp();
- // WebStateImpl object is needed here to have access to CRWSessionController
- // for setting up NavigationManager entries.
- std::unique_ptr<web::WebStateImpl> web_state(
- new web::WebStateImpl(GetBrowserState()));
- web_state->GetNavigationManagerImpl().InitializeSession(NO);
- web_state->SetWebUsageEnabled(true);
- web_state_.reset(web_state.release());
+ web::NavigationItem* GetItemAtIndex(size_t index) const override {
+ return items_[index].get();
+ }
+
+ // Adds a new navigation item of |transition| type at the end of this
+ // navigation manager.
+ void AddItem(const std::string& url_spec, ui::PageTransition transition) {
Eugene But (OOO till 7-30) 2017/03/13 21:05:41 This could be useful for other tests. Could you pl
pkl (ping after 24h if needed) 2017/03/14 02:12:48 Moved to test_navigation_manager.mm
+ items_.push_back(web::NavigationItem::Create());
+ items_.back()->SetTransitionType(transition);
+ items_.back()->SetURL(GURL(url_spec));
}
- void TearDown() override {
- web_state_.reset();
- web::WebTest::TearDown();
+ private:
+ web::ScopedNavigationItemList items_;
+};
+
+// Tests the implementation of IsLinkNavigation(). The function being tested
+// uses public NavigationManager interfaces and can be tested by using
+// TestNavigationManager that implements the same interface.
+class NativeAppNavigationUtilsTest : public PlatformTest {
+ protected:
+ void SetUp() override {
+ PlatformTest::SetUp();
+ std::unique_ptr<TestNavigationManager> test_navigation_manager =
+ base::MakeUnique<TestNavigationManager>();
+ test_navigation_manager_ = test_navigation_manager.get();
+ test_web_state_.SetNavigationManager(std::move(test_navigation_manager));
}
- web::WebState* web_state() { return web_state_->GetWebState(); }
+ web::WebState* web_state() { return &test_web_state_; }
+ // Adds a navigation item of |transition| type to current WebState.
void AddItem(const std::string& url_spec, ui::PageTransition transition) {
- CRWSessionController* session_controller =
- web_state_->GetNavigationManagerImpl().GetSessionController();
- web_state_->GetNavigationManagerImpl().AddPendingItem(
- GURL(url_spec), web::Referrer(), transition,
- web::NavigationInitiationType::USER_INITIATED);
- [session_controller commitPendingItem];
+ test_navigation_manager_->AddItem(url_spec, transition);
}
private:
- std::unique_ptr<web::WebStateImpl> web_state_;
+ TestNavigationManager* test_navigation_manager_;
+ web::TestWebState test_web_state_;
};
// Tests that default state is not a link click.
@@ -95,5 +110,3 @@ TEST_F(NativeAppNavigationUtilsTest, TestTypedUrlWithRedirectEarlier) {
AddItem("http://blah.com/page2", ui::PAGE_TRANSITION_TYPED);
EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
}
-
-} // namespace
« no previous file with comments | « ios/chrome/browser/native_app_launcher/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698