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

Unified Diff: ios/shared/chrome/browser/tabs/web_state_opener_unittest.mm

Issue 2766413004: [ios] Change API to inform WebStateList of opener-opened relationship. (Closed)
Patch Set: Address comments. 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/shared/chrome/browser/tabs/web_state_opener.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/shared/chrome/browser/tabs/web_state_opener_unittest.mm
diff --git a/ios/shared/chrome/browser/tabs/web_state_opener_unittest.mm b/ios/shared/chrome/browser/tabs/web_state_opener_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1e5a0939182df3323c545752f09725296292f1bc
--- /dev/null
+++ b/ios/shared/chrome/browser/tabs/web_state_opener_unittest.mm
@@ -0,0 +1,76 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/shared/chrome/browser/tabs/web_state_opener.h"
+
+#include <memory>
+
+#include "base/memory/ptr_util.h"
+#import "ios/web/public/test/fakes/test_navigation_manager.h"
+#import "ios/web/public/test/fakes/test_web_state.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+namespace {
+
+class FakeNavigationManager : public web::TestNavigationManager {
+ public:
+ explicit FakeNavigationManager(int last_committed_item_index)
+ : last_committed_item_index_(last_committed_item_index) {}
+
+ // web::NavigationManager implementation.
+ int GetLastCommittedItemIndex() const override {
+ return last_committed_item_index_;
+ }
+
+ private:
+ int last_committed_item_index_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeNavigationManager);
+};
+
+} // namespace
+
+class WebStateOpenerTest : public PlatformTest {
+ public:
+ WebStateOpenerTest() = default;
+
+ std::unique_ptr<web::WebState> CreateWebState(int last_committed_item_index) {
+ auto test_web_state = base::MakeUnique<web::TestWebState>();
+ test_web_state->SetNavigationManager(
+ base::MakeUnique<FakeNavigationManager>(last_committed_item_index));
+ // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required.
+ return std::move(test_web_state);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebStateOpenerTest);
+};
+
+TEST_F(WebStateOpenerTest, NullWebState) {
+ WebStateOpener opener(nullptr);
+
+ EXPECT_EQ(nullptr, opener.opener);
+ EXPECT_EQ(-1, opener.navigation_index);
+}
+
+TEST_F(WebStateOpenerTest, DefaultNavigationIndex) {
+ std::unique_ptr<web::WebState> web_state = CreateWebState(2);
+ WebStateOpener opener(web_state.get());
+
+ EXPECT_EQ(web_state.get(), opener.opener);
+ EXPECT_EQ(2, opener.navigation_index);
+}
+
+TEST_F(WebStateOpenerTest, ExplicitNavigationIndex) {
+ std::unique_ptr<web::WebState> web_state = CreateWebState(2);
+ WebStateOpener opener(web_state.get(), 1);
+
+ EXPECT_EQ(web_state.get(), opener.opener);
+ EXPECT_EQ(1, opener.navigation_index);
+}
« no previous file with comments | « ios/shared/chrome/browser/tabs/web_state_opener.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698