OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
6 #import <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
7 | 7 |
8 #include "base/mac/bind_objc_block.h" | 8 #include "base/mac/bind_objc_block.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #import "base/test/ios/wait_util.h" | 13 #import "base/test/ios/wait_util.h" |
14 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
15 #include "ios/chrome/browser/experimental_flags.h" | 15 #include "ios/chrome/browser/experimental_flags.h" |
16 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" | 16 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" |
17 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" | 17 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" |
18 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" | 18 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" |
19 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" | 19 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" |
20 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" | 20 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" |
21 #include "ios/chrome/browser/ui/ui_util.h" | 21 #include "ios/chrome/browser/ui/ui_util.h" |
22 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 22 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
23 #include "ios/chrome/grit/ios_strings.h" | 23 #include "ios/chrome/grit/ios_strings.h" |
24 #import "ios/chrome/test/app/chrome_test_util.h" | 24 #import "ios/chrome/test/app/chrome_test_util.h" |
25 #import "ios/chrome/test/app/histogram_test_util.h" | 25 #import "ios/chrome/test/app/histogram_test_util.h" |
26 #include "ios/chrome/test/app/navigation_test_util.h" | 26 #include "ios/chrome/test/app/navigation_test_util.h" |
27 #import "ios/chrome/test/app/tab_test_util.h" | 27 #import "ios/chrome/test/app/tab_test_util.h" |
28 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 28 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 29 #import "ios/chrome/test/earl_grey/chrome_actions.h" |
29 #import "ios/chrome/test/earl_grey/chrome_assertions.h" | 30 #import "ios/chrome/test/earl_grey/chrome_assertions.h" |
30 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 31 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
31 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 32 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
32 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 33 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
33 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 34 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
34 #import "ios/testing/wait_util.h" | 35 #import "ios/testing/wait_util.h" |
35 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 36 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
36 #import "ios/web/public/test/http_server.h" | 37 #import "ios/web/public/test/http_server.h" |
37 #import "ios/web/public/test/http_server_util.h" | 38 #import "ios/web/public/test/http_server_util.h" |
38 #include "ios/web/public/test/response_providers/delayed_response_provider.h" | 39 #include "ios/web/public/test/response_providers/delayed_response_provider.h" |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 destinationURL.spec().c_str()); | 835 destinationURL.spec().c_str()); |
835 responses[destinationURL] = "Whee!"; | 836 responses[destinationURL] = "Whee!"; |
836 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); | 837 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); |
837 chrome_test_util::HistogramTester histogramTester; | 838 chrome_test_util::HistogramTester histogramTester; |
838 ResetTabUsageRecorder(); | 839 ResetTabUsageRecorder(); |
839 | 840 |
840 // Open a tab with a link to click. | 841 // Open a tab with a link to click. |
841 NewMainTabWithURL(initialURL, "link"); | 842 NewMainTabWithURL(initialURL, "link"); |
842 | 843 |
843 int numberOfTabs = chrome_test_util::GetMainTabCount(); | 844 int numberOfTabs = chrome_test_util::GetMainTabCount(); |
844 [[EarlGrey | 845 id<GREYMatcher> webViewMatcher = |
845 selectElementWithMatcher:chrome_test_util::WebViewContainingText("link")] | 846 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); |
846 performAction:grey_longPress()]; | 847 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| 848 performAction:chrome_test_util::LongPressElementForContextMenu( |
| 849 "link", true /* menu should appear */)]; |
847 | 850 |
848 [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] | 851 [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] |
849 performAction:grey_tap()]; | 852 performAction:grey_tap()]; |
850 chrome_test_util::AssertMainTabCount(numberOfTabs + 1); | 853 chrome_test_util::AssertMainTabCount(numberOfTabs + 1); |
851 | 854 |
852 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent())); | 855 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent())); |
853 | 856 |
854 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 857 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
855 [[EarlGrey | 858 [[EarlGrey |
856 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] | 859 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 931 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
929 } | 932 } |
930 // The deleted tabs are purged during foregrounding and backgrounding. | 933 // The deleted tabs are purged during foregrounding and backgrounding. |
931 chrome_test_util::SimulateTabsBackgrounding(); | 934 chrome_test_util::SimulateTabsBackgrounding(); |
932 // Make sure |evicted_tabs_| purged the deleted tabs. | 935 // Make sure |evicted_tabs_| purged the deleted tabs. |
933 int evicted = chrome_test_util::GetEvictedMainTabCount(); | 936 int evicted = chrome_test_util::GetEvictedMainTabCount(); |
934 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); | 937 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); |
935 } | 938 } |
936 | 939 |
937 @end | 940 @end |
OLD | NEW |