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

Side by Side Diff: ios/shared/chrome/browser/tabs/web_state_list_order_controller_unittest.mm

Issue 2699833004: Add WebStateListOrderController to control WebState insertion. (Closed)
Patch Set: Created 3 years, 10 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
(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_list_order_controller.h"
6
7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h"
9 #import "ios/shared/chrome/browser/tabs/web_state_list.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 #include "ui/base/page_transition_types.h"
15
16 namespace {
17 const char kURL[] = "https://chromium.org/";
18
19 // A fake NavigationManager used to test opener-opened relationship in the
20 // WebStateList.
21 class FakeNavigationManer : public web::TestNavigationManager {
22 public:
23 FakeNavigationManer() = default;
24
25 // web::NavigationManager implementation.
26 int GetCurrentItemIndex() const override { return 0; }
27 int GetLastCommittedItemIndex() const override { return 0; }
28
29 DISALLOW_COPY_AND_ASSIGN(FakeNavigationManer);
30 };
31
32 } // namespace
33
34 class WebStateListOrderControllerTest : public PlatformTest {
35 public:
36 WebStateListOrderControllerTest()
37 : web_state_list_(WebStateList::WebStateOwned),
38 order_controller_(&web_state_list_) {}
39
40 protected:
41 WebStateList web_state_list_;
42 WebStateListOrderController order_controller_;
43
44 // This method should return std::unique_ptr<> however, due to the complex
45 // ownership of Tab, WebStateList currently uses raw pointers. Change this
46 // once Tab ownership is sane, see http://crbug.com/546222 for progress.
47 web::WebState* CreateWebState() {
48 auto test_web_state = base::MakeUnique<web::TestWebState>();
49 test_web_state->SetCurrentURL(GURL(kURL));
50 test_web_state->SetNavigationManager(
51 base::MakeUnique<FakeNavigationManer>());
52 return test_web_state.release();
53 }
54
55 private:
56 DISALLOW_COPY_AND_ASSIGN(WebStateListOrderControllerTest);
57 };
58
59 TEST_F(WebStateListOrderControllerTest, DetermineInsertionIndex) {
60 web_state_list_.InsertWebState(0, CreateWebState(), nullptr);
61 web_state_list_.InsertWebState(1, CreateWebState(), nullptr);
62 web::WebState* opener = web_state_list_.GetWebStateAt(0);
63
64 // Verify that first child WebState is inserted after |opener| if there are
65 // no other childs.
rohitrao (ping after 24h) 2017/02/17 13:04:12 children.
66 EXPECT_EQ(1, order_controller_.DetermineInsertionIndex(
67 ui::PAGE_TRANSITION_LINK, opener));
68
69 // Verify that child WebState is inserted at the end if it is not a "LINK"
70 // transition.
71 EXPECT_EQ(2, order_controller_.DetermineInsertionIndex(
72 ui::PAGE_TRANSITION_GENERATED, opener));
73
74 // Verify that WebState is inserted at the end if it has no opener.
75 EXPECT_EQ(2, order_controller_.DetermineInsertionIndex(
76 ui::PAGE_TRANSITION_LINK, nullptr));
77
78 // Add a child WebState to |opener|, and verify that a second child would be
79 // inserted after the first.
80 web_state_list_.InsertWebState(2, CreateWebState(), opener);
81
82 EXPECT_EQ(3, order_controller_.DetermineInsertionIndex(
83 ui::PAGE_TRANSITION_LINK, opener));
84
85 // Add a grand-child to |opener|, and verify that adding another child to
86 // |opener| would be inserted before the grand-child.
87 web_state_list_.InsertWebState(3, CreateWebState(),
88 web_state_list_.GetWebStateAt(1));
89
90 EXPECT_EQ(3, order_controller_.DetermineInsertionIndex(
91 ui::PAGE_TRANSITION_LINK, opener));
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698