Commit 271a2fec authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Nav Experiment] Add TabOrderTestCase to replace some TabModelTest cases

TabModelTest.AddWithOrderControllerAndGrouping is converted into
TabOrderTestCase/testChildTabOrdering.

TabModelTest.AddWithLinkTransitionAndIndex is removed because the
behavior it tests, i.e. child tabs being inserted before parent tab, is
not possible using public interfaces. Child tabs are always inserted
after the parent tab.

The original tests use NavigationManager::CommitPendingItem() with a
test server. This is no longer possible with WKBasedNavigationManagerImpl.
Updating the original tests to use embedded test server was rejected
because TabModel is a deprecated class. Converting them to EG test allows
the behavior to be tested with WKBasedNavigationManager and during a
future removal of TabModel.

Bug: 863026
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Ia8f2b604cab93cba38142cac384a356153e95d9b
Reviewed-on: https://chromium-review.googlesource.com/1240741
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593721}
parent dbf7a76b
...@@ -559,176 +559,6 @@ TEST_F(TabModelTest, AddWithOrderController) { ...@@ -559,176 +559,6 @@ TEST_F(TabModelTest, AddWithOrderController) {
EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1); EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1);
} }
TEST_F(TabModelTest, AddWithOrderControllerAndGrouping) {
// Create a few tabs with the controller at the front.
Tab* parent = [tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_TYPED
opener:nil
openedByDOM:NO
atIndex:[tab_model_ count]
inBackground:NO];
// Force the history to update, as it is used to determine grouping.
ASSERT_TRUE([parent navigationManagerImpl]);
[parent navigationManagerImpl]->CommitPendingItem();
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_TYPED
opener:nil
openedByDOM:NO
atIndex:[tab_model_ count]
inBackground:NO];
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_TYPED
opener:nil
openedByDOM:NO
atIndex:[tab_model_ count]
inBackground:NO];
ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true));
// Add a new tab, it should be added behind the parent.
Tab* child1 =
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_LINK
opener:parent
openedByDOM:NO
atIndex:TabModelConstants::kTabPositionAutomatically
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:parent], 0U);
EXPECT_EQ([tab_model_ indexOfTab:child1], 1U);
// Add a second child tab in the background. It should be added behind the
// first child.
Tab* child2 =
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_LINK
opener:parent
openedByDOM:NO
atIndex:TabModelConstants::kTabPositionAutomatically
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:child2], 2U);
// Navigate the parent tab to a new URL. It should not change any ordering.
web::NavigationManager::WebLoadParams parent_params(
GURL("http://www.espn.com"));
parent_params.transition_type = ui::PAGE_TRANSITION_TYPED;
[parent navigationManager]->LoadURLWithParams(parent_params);
ASSERT_TRUE([parent navigationManagerImpl]);
[parent navigationManagerImpl]->CommitPendingItem();
EXPECT_EQ([tab_model_ indexOfTab:parent], 0U);
// Add a new tab. It should be added behind the parent. It should not be added
// after the previous two children.
Tab* child3 =
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_LINK
opener:parent
openedByDOM:NO
atIndex:TabModelConstants::kTabPositionAutomatically
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:child3], 1U);
// Add a fourt child tab in the background. It should be added behind the
// third child.
Tab* child4 =
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_LINK
opener:parent
openedByDOM:NO
atIndex:TabModelConstants::kTabPositionAutomatically
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:child4], 2U);
// The first two children should have been moved to the right.
EXPECT_EQ([tab_model_ indexOfTab:child1], 3U);
EXPECT_EQ([tab_model_ indexOfTab:child2], 4U);
// Now add a non-owned tab and make sure it is added at the end.
Tab* nonChild = [tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_TYPED
opener:nil
openedByDOM:NO
atIndex:[tab_model_ count]
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:nonChild], [tab_model_ count] - 1);
}
TEST_F(TabModelTest, AddWithLinkTransitionAndIndex) {
// Create a few tabs with the controller at the front.
Tab* parent = [tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_TYPED
opener:nil
openedByDOM:NO
atIndex:[tab_model_ count]
inBackground:NO];
// Force the history to update, as it is used to determine grouping.
ASSERT_TRUE([parent navigationManagerImpl]);
[parent navigationManagerImpl]->CommitPendingItem();
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_TYPED
opener:nil
openedByDOM:NO
atIndex:[tab_model_ count]
inBackground:NO];
[tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_TYPED
opener:nil
openedByDOM:NO
atIndex:[tab_model_ count]
inBackground:NO];
ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true));
// Add a new tab, it should be added before the parent since the index
// parameter has been specified with a valid value.
Tab* child1 = [tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_LINK
opener:parent
openedByDOM:NO
atIndex:0
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:parent], 1U);
EXPECT_EQ([tab_model_ indexOfTab:child1], 0U);
// Add a new tab, it should be added at the beginning of the stack because
// the index parameter has been specified with a valid value.
Tab* child2 = [tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_LINK
opener:parent
openedByDOM:NO
atIndex:0
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:parent], 2U);
EXPECT_EQ([tab_model_ indexOfTab:child1], 1U);
EXPECT_EQ([tab_model_ indexOfTab:child2], 0U);
// Add a new tab, it should be added at position 1 because the index parameter
// has been specified with a valid value.
Tab* child3 = [tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_LINK
opener:parent
openedByDOM:NO
atIndex:1
inBackground:NO];
EXPECT_EQ([tab_model_ indexOfTab:parent], 3U);
EXPECT_EQ([tab_model_ indexOfTab:child1], 2U);
EXPECT_EQ([tab_model_ indexOfTab:child3], 1U);
EXPECT_EQ([tab_model_ indexOfTab:child2], 0U);
}
TEST_F(TabModelTest, MoveTabs) { TEST_F(TabModelTest, MoveTabs) {
Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kURL1) Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kURL1)
referrer:web::Referrer() referrer:web::Referrer()
......
...@@ -307,6 +307,7 @@ source_set("eg_tests") { ...@@ -307,6 +307,7 @@ source_set("eg_tests") {
"progress_indicator_egtest.mm", "progress_indicator_egtest.mm",
"push_and_replace_state_navigation_egtest.mm", "push_and_replace_state_navigation_egtest.mm",
"stop_loading_egtest.mm", "stop_loading_egtest.mm",
"tab_order_egtest.mm",
"visible_url_egtest.mm", "visible_url_egtest.mm",
"window_open_by_dom_egtest.mm", "window_open_by_dom_egtest.mm",
] ]
......
// Copyright 2018 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 <XCTest/XCTest.h>
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@class Tab;
using chrome_test_util::GetCurrentWebState;
using chrome_test_util::OpenLinkInNewTabButton;
using web::test::ElementSelector;
using web::WebViewInWebState;
namespace {
// This test uses test pages from in //ios/testing/data/http_server_files/.
// URL for a test page that contains a link.
const char kLinksTestURL1[] = "/links.html";
// Some text in |kLinksTestURL1|.
const char kLinksTestURL1Text[] = "Normal Link";
// ID of the <a> link in |kLinksTestURL1|.
const char kLinkSelectorID[] = "normal-link";
// URL for a different test page.
const char kLinksTestURL2[] = "/destination.html";
// Some text in |kLinksTestURL2|.
const char kLinksTestURL2Text[] = "arrived";
} // namespace
// Tests the order in which new tabs are created.
@interface TabOrderTestCase : ChromeTestCase
@end
@implementation TabOrderTestCase
// Tests that new tabs are always inserted after their parent tab.
- (void)testChildTabOrdering {
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
const GURL URL1 = self.testServer->GetURL(kLinksTestURL1);
// Create a tab that will act as the parent tab.
[ChromeEarlGrey loadURL:URL1];
[ChromeEarlGrey waitForWebViewContainingText:kLinksTestURL1Text];
Tab* parentTab = chrome_test_util::GetCurrentTab();
// Child tab should be inserted after the parent.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(GetCurrentWebState())]
performAction:chrome_test_util::LongPressElementForContextMenu(
ElementSelector::ElementSelectorId(kLinkSelectorID),
true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:2U];
Tab* childTab1 = chrome_test_util::GetNextTab();
// New child tab should be inserted AFTER |childTab1|.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(GetCurrentWebState())]
performAction:chrome_test_util::LongPressElementForContextMenu(
ElementSelector::ElementSelectorId(kLinkSelectorID),
true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:3U];
GREYAssertEqual(childTab1, chrome_test_util::GetNextTab(),
@"Unexpected next tab");
// Navigate the parent tab away and again to |kLinksTestURL1| to break
// grouping with the current child tabs. Total number of tabs should not
// change.
const GURL URL2 = self.testServer->GetURL(kLinksTestURL2);
[ChromeEarlGrey loadURL:URL2];
[ChromeEarlGrey waitForWebViewContainingText:kLinksTestURL2Text];
GREYAssertEqual(3U, chrome_test_util::GetMainTabCount(),
@"Unexpected number of tabs");
[ChromeEarlGrey loadURL:URL1];
[ChromeEarlGrey waitForWebViewContainingText:kLinksTestURL1Text];
GREYAssertEqual(3U, chrome_test_util::GetMainTabCount(),
@"Unexpected number of tabs");
// New child tab should be inserted BEFORE |childTab1|.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(GetCurrentWebState())]
performAction:chrome_test_util::LongPressElementForContextMenu(
ElementSelector::ElementSelectorId(kLinkSelectorID),
true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:4U];
Tab* childTab3 = chrome_test_util::GetNextTab();
GREYAssertNotEqual(childTab1, childTab3, @"Unexpected next tab");
// New child tab should be inserted AFTER |childTab3|.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(GetCurrentWebState())]
performAction:chrome_test_util::LongPressElementForContextMenu(
ElementSelector::ElementSelectorId(kLinkSelectorID),
true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:5U];
GREYAssertEqual(childTab3, chrome_test_util::GetNextTab(),
@"Unexpected next tab");
// Verify that |childTab1| is now at index 3.
chrome_test_util::SelectTabAtIndexInCurrentMode(3);
GREYAssertEqual(childTab1, chrome_test_util::GetCurrentTab(),
@"Unexpected current tab");
// Add a non-owned tab. It should be added at the end and marked as the
// current tab. Next tab should wrap back to index 0, the original parent tab.
chrome_test_util::OpenNewTab();
[ChromeEarlGrey waitForMainTabCount:6U];
GREYAssertEqual(parentTab, chrome_test_util::GetNextTab(),
@"Unexpected next tab");
// Verify that |anotherTab| is at index 5.
Tab* anotherTab = chrome_test_util::GetCurrentTab();
chrome_test_util::SelectTabAtIndexInCurrentMode(5);
GREYAssertEqual(anotherTab, chrome_test_util::GetCurrentTab(),
@"Unexpected current tab");
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment