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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/shared/chrome/browser/tabs/web_state_opener.h"
6
7 #include <memory>
8
9 #include "base/memory/ptr_util.h"
10 #import "ios/web/public/test/fakes/test_navigation_manager.h"
11 #import "ios/web/public/test/fakes/test_web_state.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h"
14
15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support."
17 #endif
18
19 namespace {
20
21 class FakeNavigationManager : public web::TestNavigationManager {
22 public:
23 explicit FakeNavigationManager(int last_committed_item_index)
24 : last_committed_item_index_(last_committed_item_index) {}
25
26 // web::NavigationManager implementation.
27 int GetLastCommittedItemIndex() const override {
28 return last_committed_item_index_;
29 }
30
31 private:
32 int last_committed_item_index_;
33
34 DISALLOW_COPY_AND_ASSIGN(FakeNavigationManager);
35 };
36
37 } // namespace
38
39 class WebStateOpenerTest : public PlatformTest {
40 public:
41 WebStateOpenerTest() = default;
42
43 std::unique_ptr<web::WebState> CreateWebState(int last_committed_item_index) {
44 auto test_web_state = base::MakeUnique<web::TestWebState>();
45 test_web_state->SetNavigationManager(
46 base::MakeUnique<FakeNavigationManager>(last_committed_item_index));
47 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required.
48 return std::move(test_web_state);
49 }
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(WebStateOpenerTest);
53 };
54
55 TEST_F(WebStateOpenerTest, NullWebState) {
56 WebStateOpener opener(nullptr);
57
58 EXPECT_EQ(nullptr, opener.opener);
59 EXPECT_EQ(-1, opener.navigation_index);
60 }
61
62 TEST_F(WebStateOpenerTest, DefaultNavigationIndex) {
63 std::unique_ptr<web::WebState> web_state = CreateWebState(2);
64 WebStateOpener opener(web_state.get());
65
66 EXPECT_EQ(web_state.get(), opener.opener);
67 EXPECT_EQ(2, opener.navigation_index);
68 }
69
70 TEST_F(WebStateOpenerTest, ExplicitNavigationIndex) {
71 std::unique_ptr<web::WebState> web_state = CreateWebState(2);
72 WebStateOpener opener(web_state.get(), 1);
73
74 EXPECT_EQ(web_state.get(), opener.opener);
75 EXPECT_EQ(1, opener.navigation_index);
76 }
OLDNEW
« 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