OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 #import "ios/shared/chrome/browser/tabs/web_state_list_order_controller.h" | 5 #import "ios/shared/chrome/browser/tabs/web_state_list_order_controller.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #import "ios/shared/chrome/browser/tabs/fake_web_state_list_delegate.h" | 9 #import "ios/shared/chrome/browser/tabs/fake_web_state_list_delegate.h" |
10 #import "ios/shared/chrome/browser/tabs/web_state_list.h" | 10 #import "ios/shared/chrome/browser/tabs/web_state_list.h" |
| 11 #import "ios/shared/chrome/browser/tabs/web_state_opener.h" |
11 #import "ios/web/public/test/fakes/test_navigation_manager.h" | 12 #import "ios/web/public/test/fakes/test_navigation_manager.h" |
12 #import "ios/web/public/test/fakes/test_web_state.h" | 13 #import "ios/web/public/test/fakes/test_web_state.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
15 #include "ui/base/page_transition_types.h" | 16 #include "ui/base/page_transition_types.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 const char kURL[] = "https://chromium.org/"; | 19 const char kURL[] = "https://chromium.org/"; |
19 | 20 |
20 // A fake NavigationManager used to test opener-opened relationship in the | 21 // A fake NavigationManager used to test opener-opened relationship in the |
(...skipping 30 matching lines...) Expand all Loading... |
51 test_web_state->SetNavigationManager( | 52 test_web_state->SetNavigationManager( |
52 base::MakeUnique<FakeNavigationManager>()); | 53 base::MakeUnique<FakeNavigationManager>()); |
53 return test_web_state.release(); | 54 return test_web_state.release(); |
54 } | 55 } |
55 | 56 |
56 private: | 57 private: |
57 DISALLOW_COPY_AND_ASSIGN(WebStateListOrderControllerTest); | 58 DISALLOW_COPY_AND_ASSIGN(WebStateListOrderControllerTest); |
58 }; | 59 }; |
59 | 60 |
60 TEST_F(WebStateListOrderControllerTest, DetermineInsertionIndex) { | 61 TEST_F(WebStateListOrderControllerTest, DetermineInsertionIndex) { |
61 web_state_list_.InsertWebState(0, CreateWebState(), nullptr); | 62 web_state_list_.InsertWebState(0, CreateWebState()); |
62 web_state_list_.InsertWebState(1, CreateWebState(), nullptr); | 63 web_state_list_.InsertWebState(1, CreateWebState()); |
63 web::WebState* opener = web_state_list_.GetWebStateAt(0); | 64 web::WebState* opener = web_state_list_.GetWebStateAt(0); |
64 | 65 |
65 // Verify that first child WebState is inserted after |opener| if there are | 66 // Verify that first child WebState is inserted after |opener| if there are |
66 // no other children. | 67 // no other children. |
67 EXPECT_EQ(1, order_controller_.DetermineInsertionIndex( | 68 EXPECT_EQ(1, order_controller_.DetermineInsertionIndex( |
68 ui::PAGE_TRANSITION_LINK, opener)); | 69 ui::PAGE_TRANSITION_LINK, opener)); |
69 | 70 |
70 // Verify that child WebState is inserted at the end if it is not a "LINK" | 71 // Verify that child WebState is inserted at the end if it is not a "LINK" |
71 // transition. | 72 // transition. |
72 EXPECT_EQ(2, order_controller_.DetermineInsertionIndex( | 73 EXPECT_EQ(2, order_controller_.DetermineInsertionIndex( |
73 ui::PAGE_TRANSITION_GENERATED, opener)); | 74 ui::PAGE_TRANSITION_GENERATED, opener)); |
74 | 75 |
75 // Verify that WebState is inserted at the end if it has no opener. | 76 // Verify that WebState is inserted at the end if it has no opener. |
76 EXPECT_EQ(2, order_controller_.DetermineInsertionIndex( | 77 EXPECT_EQ(2, order_controller_.DetermineInsertionIndex( |
77 ui::PAGE_TRANSITION_LINK, nullptr)); | 78 ui::PAGE_TRANSITION_LINK, nullptr)); |
78 | 79 |
79 // Add a child WebState to |opener|, and verify that a second child would be | 80 // Add a child WebState to |opener|, and verify that a second child would be |
80 // inserted after the first. | 81 // inserted after the first. |
81 web_state_list_.InsertWebState(2, CreateWebState(), opener); | 82 web_state_list_.InsertWebState(2, CreateWebState()); |
| 83 web_state_list_.SetOpenerOfWebStateAt(2, WebStateOpener(opener)); |
82 | 84 |
83 EXPECT_EQ(3, order_controller_.DetermineInsertionIndex( | 85 EXPECT_EQ(3, order_controller_.DetermineInsertionIndex( |
84 ui::PAGE_TRANSITION_LINK, opener)); | 86 ui::PAGE_TRANSITION_LINK, opener)); |
85 | 87 |
86 // Add a grand-child to |opener|, and verify that adding another child to | 88 // Add a grand-child to |opener|, and verify that adding another child to |
87 // |opener| would be inserted before the grand-child. | 89 // |opener| would be inserted before the grand-child. |
88 web_state_list_.InsertWebState(3, CreateWebState(), | 90 web_state_list_.InsertWebState(3, CreateWebState()); |
89 web_state_list_.GetWebStateAt(1)); | 91 web_state_list_.SetOpenerOfWebStateAt( |
| 92 3, WebStateOpener(web_state_list_.GetWebStateAt(1))); |
90 | 93 |
91 EXPECT_EQ(3, order_controller_.DetermineInsertionIndex( | 94 EXPECT_EQ(3, order_controller_.DetermineInsertionIndex( |
92 ui::PAGE_TRANSITION_LINK, opener)); | 95 ui::PAGE_TRANSITION_LINK, opener)); |
93 } | 96 } |
OLD | NEW |