Commit 67524868 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

[EG2] Convert RL test to EG2

Change-Id: I8e294d3c99382336ec425c67bb43a29cabdf89df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1889871
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712085}
parent bfe933e5
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "components/reading_list/core/reading_list_model.h" #include "components/reading_list/core/reading_list_model.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/reading_list/reading_list_distiller_page_factory.h" #include "ios/chrome/browser/reading_list/reading_list_distiller_page_factory.h"
#include "net/base/network_change_notifier.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace { namespace {
...@@ -70,8 +71,7 @@ ReadingListDownloadService::ReadingListDownloadService( ...@@ -70,8 +71,7 @@ ReadingListDownloadService::ReadingListDownloadService(
distiller_page_factory) distiller_page_factory)
: reading_list_model_(reading_list_model), : reading_list_model_(reading_list_model),
chrome_profile_path_(chrome_profile_path), chrome_profile_path_(chrome_profile_path),
had_connection_( had_connection_(!net::NetworkChangeNotifier::IsOffline()),
!GetApplicationContext()->GetNetworkConnectionTracker()->IsOffline()),
distiller_page_factory_(std::move(distiller_page_factory)), distiller_page_factory_(std::move(distiller_page_factory)),
distiller_factory_(std::move(distiller_factory)), distiller_factory_(std::move(distiller_factory)),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
...@@ -208,7 +208,7 @@ void ReadingListDownloadService::DownloadEntry(const GURL& url) { ...@@ -208,7 +208,7 @@ void ReadingListDownloadService::DownloadEntry(const GURL& url) {
entry->DistilledState() == ReadingListEntry::PROCESSED || entry->IsRead()) entry->DistilledState() == ReadingListEntry::PROCESSED || entry->IsRead())
return; return;
if (GetApplicationContext()->GetNetworkConnectionTracker()->IsOffline()) { if (net::NetworkChangeNotifier::IsOffline()) {
// There is no connection, save it for download only if we did not exceed // There is no connection, save it for download only if we did not exceed
// the maximaxum number of tries. // the maximaxum number of tries.
if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeWifiOnly) if (entry->FailedDownloadCounter() < kNumberOfFailsBeforeWifiOnly)
......
...@@ -69,6 +69,14 @@ source_set("reading_list") { ...@@ -69,6 +69,14 @@ source_set("reading_list") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
} }
source_set("reading_list_constants") {
sources = [
"reading_list_constants.h",
"reading_list_constants.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("reading_list_ui") { source_set("reading_list_ui") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
...@@ -85,8 +93,6 @@ source_set("reading_list_ui") { ...@@ -85,8 +93,6 @@ source_set("reading_list_ui") {
"reading_list_table_view_controller.h", "reading_list_table_view_controller.h",
"reading_list_table_view_controller.mm", "reading_list_table_view_controller.mm",
"reading_list_toolbar_button_commands.h", "reading_list_toolbar_button_commands.h",
"reading_list_toolbar_button_identifiers.h",
"reading_list_toolbar_button_identifiers.mm",
"reading_list_toolbar_button_manager.h", "reading_list_toolbar_button_manager.h",
"reading_list_toolbar_button_manager.mm", "reading_list_toolbar_button_manager.mm",
"reading_list_ui_distillation_status.h", "reading_list_ui_distillation_status.h",
...@@ -94,6 +100,7 @@ source_set("reading_list_ui") { ...@@ -94,6 +100,7 @@ source_set("reading_list_ui") {
"text_badge_view.mm", "text_badge_view.mm",
] ]
deps = [ deps = [
":reading_list_constants",
"resources:reading_list_empty_state", "resources:reading_list_empty_state",
"resources:reading_list_empty_state_new", "resources:reading_list_empty_state_new",
"resources:reading_list_tools_icon", "resources:reading_list_tools_icon",
...@@ -158,6 +165,7 @@ source_set("unit_tests") { ...@@ -158,6 +165,7 @@ source_set("unit_tests") {
} }
source_set("eg_tests") { source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
sources = [ sources = [
...@@ -165,7 +173,9 @@ source_set("eg_tests") { ...@@ -165,7 +173,9 @@ source_set("eg_tests") {
] ]
deps = [ deps = [
":reading_list", ":reading_list",
":reading_list_constants",
":reading_list_ui", ":reading_list_ui",
":test_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/reading_list/core", "//components/reading_list/core",
...@@ -176,6 +186,7 @@ source_set("eg_tests") { ...@@ -176,6 +186,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/popup_menu:constants", "//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/table_view", "//ios/chrome/browser/ui/table_view",
"//ios/chrome/browser/ui/table_view:constants",
"//ios/chrome/browser/ui/table_view:feature_flags", "//ios/chrome/browser/ui/table_view:feature_flags",
"//ios/chrome/browser/ui/table_view:views", "//ios/chrome/browser/ui/table_view:views",
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
...@@ -196,3 +207,88 @@ source_set("eg_tests") { ...@@ -196,3 +207,88 @@ source_set("eg_tests") {
"XCTest.framework", "XCTest.framework",
] ]
} }
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"reading_list_egtest.mm",
]
deps = [
":eg_test_support+eg2",
":reading_list_constants",
"//base",
"//base/test:test_support",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/table_view:constants",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/navigation:navigation",
"//net",
"//net:test_support",
]
libs = [ "UIKit.framework" ]
}
source_set("test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"reading_list_app_interface.h",
"reading_list_app_interface.mm",
]
deps = [
"//base/test:test_support",
"//base/test:test_support",
"//components/reading_list/core",
"//ios/chrome/browser/reading_list",
"//ios/chrome/test/app:test_support",
"//ios/testing:nserror_support",
"//ios/testing/earl_grey:earl_grey_support",
]
}
source_set("eg_app_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"reading_list_app_interface.h",
"reading_list_app_interface.mm",
]
deps = [
"//base/test:test_support",
"//components/reading_list/core",
"//ios/chrome/browser/reading_list",
"//ios/chrome/test/app:test_support",
"//ios/testing:nserror_support",
]
}
source_set("eg_test_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"reading_list_app_interface.h",
"reading_list_app_interface_stub.mm",
]
deps = [
"//base",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
]
}
// Copyright 2019 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.
#ifndef IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_APP_INTERFACE_H_
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include "base/compiler_specific.h"
// ReadingListAppInterface contains the app-side
// implementation for helpers. These helpers are compiled into
// the app binary and can be called from either app or test code.
@interface ReadingListAppInterface : NSObject
// Whether offline pages are displayed in a native content (NO) or the main
// WKWebView (YES).
+ (BOOL)isOfflinePageWithoutNativeContentEnabled;
// Removes all entries in the ReadingListModel.
+ (NSError*)clearEntries WARN_UNUSED_RESULT;
// Adds an entry in the ReadingListModel.
+ (NSError*)addEntryWithURL:(NSURL*)url
title:(NSString*)title
read:(BOOL)read WARN_UNUSED_RESULT;
// The number of read entries in the ReadingListModel.
+ (NSInteger)readEntriesCount;
// The number of unread entries in the ReadingListModel.
+ (NSInteger)unreadEntriesCount;
// Checks whether the current webState has a StaticHTML view contaning |text|.
// This is only used when |isOfflinePageWithoutNativeContentEnabled| is NO.
+ (BOOL)staticHTMLViewContainingText:(NSString*)text;
// Simulate that the current connection is WiFI.
+ (void)forceConnectionToWifi;
// Sends a notification that connection is WiFi.
+ (void)notifyWifiConnection;
// Reset the connection type.
+ (void)resetConnectionType;
@end
#endif // IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_APP_INTERFACE_H_
// Copyright 2019 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 "ios/chrome/browser/ui/reading_list/reading_list_app_interface.h"
#include "base/memory/singleton.h"
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "components/reading_list/core/reading_list_model.h"
#include "ios/chrome/browser/reading_list/features.h"
#include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/static_html_view_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/testing/nserror_util.h"
#include "net/base/mac/url_conversions.h"
#include "net/base/network_change_notifier.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Returns the reading list model.
ReadingListModel* GetReadingListModel(NSError** error) {
ReadingListModel* model =
ReadingListModelFactory::GetInstance()->GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
if (!base::test::ios::WaitUntilConditionOrTimeout(2, ^{
return model->loaded();
})) {
*error = testing::NSErrorWithLocalizedDescription(
@"Reading List model did not load");
}
return model;
}
// Overrides the NetworkChangeNotifier to enable distillation even if the device
// does not have network.
class WifiNetworkChangeNotifier : public net::NetworkChangeNotifier {
public:
WifiNetworkChangeNotifier() : net::NetworkChangeNotifier() {}
ConnectionType GetCurrentConnectionType() const override {
return CONNECTION_WIFI;
}
private:
DISALLOW_COPY_AND_ASSIGN(WifiNetworkChangeNotifier);
};
// Overrides the NetworkChangeNotifier to enable distillation even if the device
// does not have network.
class ConnectionTypeOverrider {
public:
static ConnectionTypeOverrider* SharedInstance() {
return base::Singleton<ConnectionTypeOverrider>::get();
}
ConnectionTypeOverrider() {}
void OverrideConnectionType() {
network_change_disabler_.reset(
new net::NetworkChangeNotifier::DisableForTest());
wifi_network_.reset(new WifiNetworkChangeNotifier());
}
void ResetConnectionType() {
wifi_network_.reset();
network_change_disabler_.reset();
}
private:
std::unique_ptr<net::NetworkChangeNotifier::DisableForTest>
network_change_disabler_;
std::unique_ptr<WifiNetworkChangeNotifier> wifi_network_;
DISALLOW_COPY_AND_ASSIGN(ConnectionTypeOverrider);
};
} // namespace
@implementation ReadingListAppInterface
+ (NSError*)clearEntries {
NSError* error = nil;
ReadingListModel* model = GetReadingListModel(&error);
if (error) {
return error;
}
for (const GURL& url : model->Keys())
model->RemoveEntryByURL(url);
return nil;
}
+ (NSError*)addEntryWithURL:(NSURL*)url title:(NSString*)title read:(BOOL)read {
NSError* error = nil;
ReadingListModel* model = GetReadingListModel(&error);
if (error) {
return error;
}
model->AddEntry(net::GURLWithNSURL(url), base::SysNSStringToUTF8(title),
reading_list::ADDED_VIA_CURRENT_APP);
if (read) {
model->SetReadStatus(net::GURLWithNSURL(url), true);
}
return error;
}
+ (NSInteger)readEntriesCount {
NSError* error = nil;
ReadingListModel* model = GetReadingListModel(&error);
if (error) {
return -1;
}
return model->size() - model->unread_size();
}
+ (NSInteger)unreadEntriesCount {
NSError* error = nil;
ReadingListModel* model = GetReadingListModel(&error);
if (error) {
return -1;
}
return model->unread_size();
}
+ (BOOL)staticHTMLViewContainingText:(NSString*)text {
return chrome_test_util::StaticHtmlViewContainingText(
chrome_test_util::GetCurrentWebState(), base::SysNSStringToUTF8(text));
}
+ (BOOL)isOfflinePageWithoutNativeContentEnabled {
return reading_list::IsOfflinePageWithoutNativeContentEnabled();
}
+ (void)forceConnectionToWifi {
ConnectionTypeOverrider::SharedInstance()->OverrideConnectionType();
}
+ (void)notifyWifiConnection {
if (net::NetworkChangeNotifier::IsOffline()) {
net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
net::NetworkChangeNotifier::CONNECTION_WIFI);
}
}
+ (void)resetConnectionType {
ConnectionTypeOverrider::SharedInstance()->ResetConnectionType();
}
@end
// Copyright 2019 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 "ios/chrome/browser/ui/reading_list/reading_list_app_interface.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#if defined(CHROME_EARL_GREY_2)
// TODO(crbug.com/1015113): The EG2 macro is breaking indexing for some reason
// without the trailing semicolon. For now, disable the extra semi warning
// so Xcode indexing works for the egtest.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-extra-semi"
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ReadingListAppInterface);
#pragma clang diagnostic pop
#endif // defined(CHROME_EARL_GREY_2)
...@@ -2,11 +2,17 @@ ...@@ -2,11 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_TOOLBAR_BUTTON_IDENTIFIERS_H_ #ifndef IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_TOOLBAR_BUTTON_IDENTIFIERS_H_ #define IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_CONSTANTS_H_
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
// Accessibility identifier for reading list view.
extern NSString* const kReadingListViewID;
// Accessibility identifier for the badge icon.
extern NSString* const kTableViewURLCellFaviconBadgeViewID;
// Accessibility identifiers for reading list toolbar buttons. // Accessibility identifiers for reading list toolbar buttons.
extern NSString* const kReadingListToolbarEditButtonID; extern NSString* const kReadingListToolbarEditButtonID;
extern NSString* const kReadingListToolbarDeleteButtonID; extern NSString* const kReadingListToolbarDeleteButtonID;
...@@ -14,4 +20,4 @@ extern NSString* const kReadingListToolbarDeleteAllReadButtonID; ...@@ -14,4 +20,4 @@ extern NSString* const kReadingListToolbarDeleteAllReadButtonID;
extern NSString* const kReadingListToolbarCancelButtonID; extern NSString* const kReadingListToolbarCancelButtonID;
extern NSString* const kReadingListToolbarMarkButtonID; extern NSString* const kReadingListToolbarMarkButtonID;
#endif // IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_TOOLBAR_BUTTON_IDENTIFIERS_H_ #endif // IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_CONSTANTS_H_
...@@ -2,12 +2,17 @@ ...@@ -2,12 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button_identifiers.h" #import "ios/chrome/browser/ui/reading_list/reading_list_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kReadingListViewID = @"ReadingListTableView";
NSString* const kTableViewURLCellFaviconBadgeViewID =
@"TableViewURLCellFaviconBadgeView";
NSString* const kReadingListToolbarEditButtonID = NSString* const kReadingListToolbarEditButtonID =
@"ReadingListToolbarEditButtonID"; @"ReadingListToolbarEditButtonID";
NSString* const kReadingListToolbarDeleteButtonID = NSString* const kReadingListToolbarDeleteButtonID =
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
...@@ -16,38 +15,27 @@ ...@@ -16,38 +15,27 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "components/reading_list/core/reading_list_model.h"
#import "ios/chrome/browser/reading_list/features.h"
#include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/ui/commands/reading_list_add_command.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h" #import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_table_view_controller.h" #import "ios/chrome/browser/ui/reading_list/reading_list_app_interface.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button_identifiers.h" #import "ios/chrome/browser/ui/reading_list/reading_list_constants.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_url_cell_favicon_badge_view.h" #import "ios/chrome/browser/ui/table_view/table_view_constants.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_url_item.h"
#import "ios/chrome/browser/ui/table_view/feature_flags.h"
#import "ios/chrome/browser/ui/table_view/table_view_empty_view.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/grit/ios_theme_resources.h" #import "ios/chrome/test/earl_grey/chrome_actions_app_interface.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/static_html_view_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/navigation/navigation_manager.h" #import "ios/web/public/navigation/navigation_manager.h"
#import "ios/web/public/navigation/reload_type.h" #import "ios/web/public/navigation/reload_type.h"
#import "ios/web/public/test/web_view_content_test_util.h"
#import "ios/web/public/web_state.h"
#include "net/base/network_change_notifier.h"
#include "net/test/embedded_test_server/default_handlers.h" #include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h" #include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h" #include "net/test/embedded_test_server/request_handler_util.h"
#include "net/base/network_change_notifier.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
...@@ -57,43 +45,29 @@ using base::test::ios::kWaitForUIElementTimeout; ...@@ -57,43 +45,29 @@ using base::test::ios::kWaitForUIElementTimeout;
namespace { namespace {
const char kContentToRemove[] = "Text that distillation should remove."; const char kContentToRemove[] = "Text that distillation should remove.";
const char kContentToKeep[] = "Text that distillation should keep."; const char kContentToKeep[] = "Text that distillation should keep.";
const char kDistillableTitle[] = "Tomato"; NSString* const kDistillableTitle = @"Tomato";
const char kDistillableURL[] = "/potato"; const char kDistillableURL[] = "/potato";
const char kNonDistillableURL[] = "/beans"; const char kNonDistillableURL[] = "/beans";
const char kReadTitle[] = "foobar"; NSString* const kReadTitle = @"foobar";
const char kReadURL[] = "http://readfoobar.com"; NSString* const kReadURL = @"http://readfoobar.com";
const char kUnreadTitle[] = "I am an unread entry"; NSString* const kUnreadTitle = @"I am an unread entry";
const char kUnreadURL[] = "http://unreadfoobar.com"; NSString* const kUnreadURL = @"http://unreadfoobar.com";
const char kReadURL2[] = "http://kReadURL2.com"; NSString* const kReadURL2 = @"http://kReadURL2.com";
const char kReadTitle2[] = "read item 2"; NSString* const kReadTitle2 = @"read item 2";
const char kUnreadTitle2[] = "I am another unread entry"; NSString* const kUnreadTitle2 = @"I am another unread entry";
const char kUnreadURL2[] = "http://unreadfoobar2.com"; NSString* const kUnreadURL2 = @"http://unreadfoobar2.com";
const size_t kNumberReadEntries = 2; const size_t kNumberReadEntries = 2;
const size_t kNumberUnreadEntries = 2; const size_t kNumberUnreadEntries = 2;
const CFTimeInterval kSnackbarAppearanceTimeout = 5; const CFTimeInterval kSnackbarAppearanceTimeout = 5;
const CFTimeInterval kSnackbarDisappearanceTimeout = // kSnackbarDisappearanceTimeout = MDCSnackbarMessageDurationMax + 1
MDCSnackbarMessageDurationMax + 1; const CFTimeInterval kSnackbarDisappearanceTimeout = 10 + 1;
const CFTimeInterval kDelayForSlowWebServer = 4; const CFTimeInterval kDelayForSlowWebServer = 4;
const CFTimeInterval kLoadOfflineTimeout = kDelayForSlowWebServer + 1; const CFTimeInterval kLoadOfflineTimeout = kDelayForSlowWebServer + 1;
const CFTimeInterval kLongPressDuration = 1.0; const CFTimeInterval kLongPressDuration = 1.0;
const CFTimeInterval kDistillationTimeout = 5; const CFTimeInterval kDistillationTimeout = 5;
const CFTimeInterval kServerOperationDelay = 1; const CFTimeInterval kServerOperationDelay = 1;
const char kReadHeader[] = "Read"; NSString* const kReadHeader = @"Read";
const char kUnreadHeader[] = "Unread"; NSString* const kUnreadHeader = @"Unread";
// Overrides the NetworkChangeNotifier to enable distillation even if the device
// does not have network.
class WifiNetworkChangeNotifier : public net::NetworkChangeNotifier {
public:
WifiNetworkChangeNotifier() : net::NetworkChangeNotifier() {}
ConnectionType GetCurrentConnectionType() const override {
return CONNECTION_WIFI;
}
private:
DISALLOW_COPY_AND_ASSIGN(WifiNetworkChangeNotifier);
};
// Returns the string concatenated |n| times. // Returns the string concatenated |n| times.
std::string operator*(const std::string& s, unsigned int n) { std::string operator*(const std::string& s, unsigned int n) {
...@@ -103,37 +77,10 @@ std::string operator*(const std::string& s, unsigned int n) { ...@@ -103,37 +77,10 @@ std::string operator*(const std::string& s, unsigned int n) {
return out.str(); return out.str();
} }
// Returns the reading list model.
ReadingListModel* GetReadingListModel() {
ReadingListModel* model =
ReadingListModelFactory::GetInstance()->GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
GREYAssert(
base::test::ios::WaitUntilConditionOrTimeout(2,
^{
return model->loaded();
}),
@"Reading List model did not load");
return model;
}
// Scroll to the top of the Reading List. // Scroll to the top of the Reading List.
void ScrollToTop() { void ScrollToTop() {
// On iOS 13 the settings menu appears as a card that can be dismissed with a [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kReadingListViewID)]
// downward swipe, for this reason we need to swipe up programatically to performAction:[ChromeActionsAppInterface scrollToTop]];
// avoid dismissing the VC.
GREYPerformBlock scrollToTopBlock =
^BOOL(id element, __strong NSError** error) {
UIScrollView* view = base::mac::ObjCCastStrict<UIScrollView>(element);
view.contentOffset = CGPointZero;
return YES;
};
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
[[ReadingListTableViewController
class] accessibilityIdentifier])]
performAction:[GREYActionBlock actionWithName:@"Scroll to top"
performBlock:scrollToTopBlock]];
} }
// Asserts that the "mark" toolbar button is visible and has the a11y label of // Asserts that the "mark" toolbar button is visible and has the a11y label of
...@@ -143,7 +90,7 @@ void AssertToolbarMarkButtonText(int a11y_label_id) { ...@@ -143,7 +90,7 @@ void AssertToolbarMarkButtonText(int a11y_label_id) {
selectElementWithMatcher: selectElementWithMatcher:
grey_allOf( grey_allOf(
grey_accessibilityID(kReadingListToolbarMarkButtonID), grey_accessibilityID(kReadingListToolbarMarkButtonID),
grey_ancestor(grey_kindOfClass([UIToolbar class])), grey_ancestor(grey_kindOfClassName(@"UIToolbar")),
chrome_test_util::ButtonWithAccessibilityLabelId(a11y_label_id), chrome_test_util::ButtonWithAccessibilityLabelId(a11y_label_id),
nil)] assertWithMatcher:grey_sufficientlyVisible()]; nil)] assertWithMatcher:grey_sufficientlyVisible()];
} }
...@@ -152,8 +99,8 @@ void AssertToolbarMarkButtonText(int a11y_label_id) { ...@@ -152,8 +99,8 @@ void AssertToolbarMarkButtonText(int a11y_label_id) {
void AssertToolbarButtonNotVisibleWithID(NSString* button_id) { void AssertToolbarButtonNotVisibleWithID(NSString* button_id) {
[[EarlGrey [[EarlGrey
selectElementWithMatcher:grey_allOf(grey_accessibilityID(button_id), selectElementWithMatcher:grey_allOf(grey_accessibilityID(button_id),
grey_ancestor(grey_kindOfClass( grey_ancestor(grey_kindOfClassName(
[UIToolbar class])), @"UIToolbar")),
nil)] nil)]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
...@@ -162,8 +109,8 @@ void AssertToolbarButtonNotVisibleWithID(NSString* button_id) { ...@@ -162,8 +109,8 @@ void AssertToolbarButtonNotVisibleWithID(NSString* button_id) {
void AssertToolbarButtonVisibleWithID(NSString* button_id) { void AssertToolbarButtonVisibleWithID(NSString* button_id) {
[[EarlGrey [[EarlGrey
selectElementWithMatcher:grey_allOf(grey_accessibilityID(button_id), selectElementWithMatcher:grey_allOf(grey_accessibilityID(button_id),
grey_ancestor(grey_kindOfClass( grey_ancestor(grey_kindOfClassName(
[UIToolbar class])), @"UIToolbar")),
nil)] nil)]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
} }
...@@ -183,45 +130,40 @@ void TapContextMenuButtonWithA11yLabelID(int a11y_label_id) { ...@@ -183,45 +130,40 @@ void TapContextMenuButtonWithA11yLabelID(int a11y_label_id) {
// Performs |action| on the entry with the title |entryTitle|. The view can be // Performs |action| on the entry with the title |entryTitle|. The view can be
// scrolled down to find the entry. // scrolled down to find the entry.
void PerformActionOnEntry(const std::string& entryTitle, void PerformActionOnEntry(NSString* entryTitle, id<GREYAction> action) {
id<GREYAction> action) {
ScrollToTop(); ScrollToTop();
id<GREYMatcher> matcher = id<GREYMatcher> matcher =
grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel(entryTitle),
base::SysUTF8ToNSString(entryTitle)), grey_ancestor(grey_kindOfClassName(@"TableViewURLCell")),
grey_ancestor(grey_kindOfClass([TableViewURLCell class])),
grey_sufficientlyVisible(), nil); grey_sufficientlyVisible(), nil);
[[[EarlGrey selectElementWithMatcher:matcher] [[[EarlGrey selectElementWithMatcher:matcher]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100) usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100)
onElementWithMatcher:grey_accessibilityID([[ReadingListTableViewController onElementWithMatcher:grey_accessibilityID(kReadingListViewID)]
class] accessibilityIdentifier])]
performAction:action]; performAction:action];
} }
// Taps the entry with the title |entryTitle|. // Taps the entry with the title |entryTitle|.
void TapEntry(const std::string& entryTitle) { void TapEntry(NSString* entryTitle) {
PerformActionOnEntry(entryTitle, grey_tap()); PerformActionOnEntry(entryTitle, grey_tap());
} }
// Long-presses the entry with the title |entryTitle|. // Long-presses the entry with the title |entryTitle|.
void LongPressEntry(const std::string& entryTitle) { void LongPressEntry(NSString* entryTitle) {
PerformActionOnEntry(entryTitle, PerformActionOnEntry(entryTitle,
grey_longPressWithDuration(kLongPressDuration)); grey_longPressWithDuration(kLongPressDuration));
} }
// Asserts that the entry with the title |entryTitle| is visible. // Asserts that the entry with the title |entryTitle| is visible.
void AssertEntryVisible(const std::string& entryTitle) { void AssertEntryVisible(NSString* entryTitle) {
ScrollToTop(); ScrollToTop();
[[[EarlGrey [[[EarlGrey
selectElementWithMatcher: selectElementWithMatcher:
grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( grey_allOf(
base::SysUTF8ToNSString(entryTitle)), chrome_test_util::StaticTextWithAccessibilityLabel(entryTitle),
grey_ancestor(grey_kindOfClass([TableViewURLCell class])), grey_ancestor(grey_kindOfClassName(@"TableViewURLCell")),
grey_sufficientlyVisible(), nil)] grey_sufficientlyVisible(), nil)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100) usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100)
onElementWithMatcher:grey_accessibilityID( onElementWithMatcher:grey_accessibilityID(kReadingListViewID)]
[[ReadingListTableViewController class]
accessibilityIdentifier])]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
} }
...@@ -240,57 +182,59 @@ void AssertAllEntriesVisible() { ...@@ -240,57 +182,59 @@ void AssertAllEntriesVisible() {
} }
// Asserts that the entry |title| is not visible. // Asserts that the entry |title| is not visible.
void AssertEntryNotVisible(std::string title) { void AssertEntryNotVisible(NSString* title) {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
ScrollToTop(); ScrollToTop();
NSError* error; NSError* error;
[[[EarlGrey [[[EarlGrey
selectElementWithMatcher: selectElementWithMatcher:
grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel(title),
base::SysUTF8ToNSString(title)), grey_ancestor(grey_kindOfClassName(@"TableViewURLCell")),
grey_ancestor(grey_kindOfClass([TableViewURLCell class])),
grey_sufficientlyVisible(), nil)] grey_sufficientlyVisible(), nil)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100) usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 100)
onElementWithMatcher:grey_accessibilityID( onElementWithMatcher:grey_accessibilityID(kReadingListViewID)]
[[ReadingListTableViewController class]
accessibilityIdentifier])]
assertWithMatcher:grey_notNil() assertWithMatcher:grey_notNil()
error:&error]; error:&error];
GREYAssertNotNil(error, @"Entry is visible"); GREYAssertNotNil(error, @"Entry is visible");
} }
// Asserts |header| is visible. // Asserts |header| is visible.
void AssertHeaderNotVisible(std::string header) { void AssertHeaderNotVisible(NSString* header) {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
ScrollToTop(); ScrollToTop();
[[EarlGrey selectElementWithMatcher:chrome_test_util:: [[EarlGrey selectElementWithMatcher:
StaticTextWithAccessibilityLabel( chrome_test_util::StaticTextWithAccessibilityLabel(header)]
base::SysUTF8ToNSString(header))]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
// Opens the reading list menu using command line. // Opens the reading list menu.
void OpenReadingList() { void OpenReadingList() {
[chrome_test_util::BrowserCommandDispatcherForMainBVC() showReadingList]; [ChromeEarlGreyUI openToolsMenu];
[ChromeEarlGreyUI
tapToolsMenuButton:chrome_test_util::ReadingListMenuButton()];
} }
// Adds 20 read and 20 unread entries to the model, opens the reading list menu // Adds 20 read and 20 unread entries to the model, opens the reading list menu
// and enter edit mode. // and enter edit mode.
void AddLotOfEntriesAndEnterEdit() { void AddLotOfEntriesAndEnterEdit() {
ReadingListModel* model = GetReadingListModel();
for (NSInteger index = 0; index < 10; index++) { for (NSInteger index = 0; index < 10; index++) {
GURL url_to_be_added = NSString* url_to_be_added =
GURL(kReadURL + std::string("/") + base::NumberToString(index)); [kReadURL stringByAppendingPathComponent:[@(index) stringValue]];
model->AddEntry(url_to_be_added, std::string(kReadTitle), GREYAssertNil([ReadingListAppInterface
reading_list::ADDED_VIA_CURRENT_APP); addEntryWithURL:[NSURL URLWithString:url_to_be_added]
model->SetReadStatus(url_to_be_added, true); title:kReadTitle
read:YES],
@"Unable to add Reading List item");
} }
for (NSInteger index = 0; index < 10; index++) { for (NSInteger index = 0; index < 10; index++) {
GURL url_to_be_added = NSString* url_to_be_added =
GURL(kUnreadURL + std::string("/") + base::NumberToString(index)); [kUnreadURL stringByAppendingPathComponent:[@(index) stringValue]];
model->AddEntry(url_to_be_added, std::string(kReadTitle), GREYAssertNil([ReadingListAppInterface
reading_list::ADDED_VIA_CURRENT_APP); addEntryWithURL:[NSURL URLWithString:url_to_be_added]
title:kReadTitle
read:NO],
@"Unable to add Reading List item");
} }
OpenReadingList(); OpenReadingList();
...@@ -300,37 +244,35 @@ void AddLotOfEntriesAndEnterEdit() { ...@@ -300,37 +244,35 @@ void AddLotOfEntriesAndEnterEdit() {
// Adds a read and an unread entry to the model, opens the reading list menu and // Adds a read and an unread entry to the model, opens the reading list menu and
// enter edit mode. // enter edit mode.
void AddEntriesAndEnterEdit() { void AddEntriesAndEnterEdit() {
ReadingListModel* model = GetReadingListModel(); GREYAssertNil(
model->AddEntry(GURL(kReadURL), std::string(kReadTitle), [ReadingListAppInterface addEntryWithURL:[NSURL URLWithString:kReadURL]
reading_list::ADDED_VIA_CURRENT_APP); title:kReadTitle
model->SetReadStatus(GURL(kReadURL), true); read:YES],
model->AddEntry(GURL(kReadURL2), std::string(kReadTitle2), @"Unable to add Reading List item");
reading_list::ADDED_VIA_CURRENT_APP); GREYAssertNil(
model->SetReadStatus(GURL(kReadURL2), true); [ReadingListAppInterface addEntryWithURL:[NSURL URLWithString:kReadURL2]
model->AddEntry(GURL(kUnreadURL), std::string(kUnreadTitle), title:kReadTitle2
reading_list::ADDED_VIA_CURRENT_APP); read:YES],
model->AddEntry(GURL(kUnreadURL2), std::string(kUnreadTitle2), @"Unable to add Reading List item");
reading_list::ADDED_VIA_CURRENT_APP); GREYAssertNil(
[ReadingListAppInterface addEntryWithURL:[NSURL URLWithString:kUnreadURL]
title:kUnreadTitle
read:NO],
@"Unable to add Reading List item");
GREYAssertNil(
[ReadingListAppInterface addEntryWithURL:[NSURL URLWithString:kUnreadURL2]
title:kUnreadTitle2
read:NO],
@"Unable to add Reading List item");
OpenReadingList(); OpenReadingList();
TapToolbarButtonWithID(kReadingListToolbarEditButtonID); TapToolbarButtonWithID(kReadingListToolbarEditButtonID);
} }
// Computes the number of read entries in the model.
size_t ModelReadSize(ReadingListModel* model) {
size_t size = 0;
for (const auto& url : model->Keys()) {
if (model->GetEntryByURL(url)->IsRead()) {
size++;
}
}
return size;
}
// Returns a match for the Reading List Empty Collection Background. // Returns a match for the Reading List Empty Collection Background.
id<GREYMatcher> EmptyBackground() { id<GREYMatcher> EmptyBackground() {
return grey_accessibilityID( return grey_accessibilityID(kTableViewEmptyViewID);
[[TableViewEmptyView class] accessibilityIdentifier]);
} }
// Adds the current page to the Reading List. // Adds the current page to the Reading List.
...@@ -367,20 +309,17 @@ void AddCurrentPageToReadingList() { ...@@ -367,20 +309,17 @@ void AddCurrentPageToReadingList() {
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout( GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
kSnackbarDisappearanceTimeout, wait_for_disappearance), kSnackbarDisappearanceTimeout, wait_for_disappearance),
@"Snackbar did not disappear."); @"Snackbar did not disappear.");
if (net::NetworkChangeNotifier::IsOffline()) { [ReadingListAppInterface notifyWifiConnection];
net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
net::NetworkChangeNotifier::CONNECTION_WIFI);
}
} }
// Wait until one element is distilled. // Wait until one element is distilled.
void WaitForDistillation() { void WaitForDistillation() {
NSString* a11y_id =
[TableViewURLCellFaviconBadgeView accessibilityIdentifier];
ConditionBlock wait_for_distillation_date = ^{ ConditionBlock wait_for_distillation_date = ^{
NSError* error = nil; NSError* error = nil;
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(a11y_id)] [[EarlGrey
assertWithMatcher:grey_notNil() selectElementWithMatcher:grey_accessibilityID(
kTableViewURLCellFaviconBadgeViewID)]
assertWithMatcher:grey_sufficientlyVisible()
error:&error]; error:&error];
return error == nil; return error == nil;
}; };
...@@ -434,9 +373,7 @@ void OpenPageSecurityInfoBubble() { ...@@ -434,9 +373,7 @@ void OpenPageSecurityInfoBubble() {
void WaitForStaticHtmlViewContainingText(NSString* text) { void WaitForStaticHtmlViewContainingText(NSString* text) {
bool has_static_view = bool has_static_view =
base::test::ios::WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{ base::test::ios::WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{
return chrome_test_util::StaticHtmlViewContainingText( return [ReadingListAppInterface staticHTMLViewContainingText:text];
chrome_test_util::GetCurrentWebState(),
base::SysNSStringToUTF8(text));
}); });
NSString* error_description = [NSString NSString* error_description = [NSString
...@@ -450,9 +387,7 @@ void WaitForStaticHtmlViewContainingText(NSString* text) { ...@@ -450,9 +387,7 @@ void WaitForStaticHtmlViewContainingText(NSString* text) {
void WaitForStaticHtmlViewNotContainingText(NSString* text) { void WaitForStaticHtmlViewNotContainingText(NSString* text) {
bool no_static_view = bool no_static_view =
base::test::ios::WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{ base::test::ios::WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{
return !chrome_test_util::StaticHtmlViewContainingText( return ![ReadingListAppInterface staticHTMLViewContainingText:text];
chrome_test_util::GetCurrentWebState(),
base::SysNSStringToUTF8(text));
}); });
NSString* error_description = [NSString NSString* error_description = [NSString
...@@ -499,9 +434,8 @@ void AssertIsShowingDistillablePageNativeContent(bool online, ...@@ -499,9 +434,8 @@ void AssertIsShowingDistillablePageNativeContent(bool online,
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout( GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
kLoadOfflineTimeout, kLoadOfflineTimeout,
^bool { ^bool {
return web::test::IsWebViewContainingText( return [ChromeEarlGreyAppInterface
chrome_test_util::GetCurrentWebState(), webStateContainsText:@(kContentToKeep)];
kContentToKeep);
}), }),
@"Waiting for online page."); @"Waiting for online page.");
} else { } else {
...@@ -533,7 +467,7 @@ void AssertIsShowingDistillablePageNativeContent(bool online, ...@@ -533,7 +467,7 @@ void AssertIsShowingDistillablePageNativeContent(bool online,
// Tests that the correct version of kDistillableURL is displayed. // Tests that the correct version of kDistillableURL is displayed.
void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
if (reading_list::IsOfflinePageWithoutNativeContentEnabled()) { if ([ReadingListAppInterface isOfflinePageWithoutNativeContentEnabled]) {
return AssertIsShowingDistillablePageNoNativeContent(online, return AssertIsShowingDistillablePageNoNativeContent(online,
distillable_url); distillable_url);
} }
...@@ -550,7 +484,6 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -550,7 +484,6 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// The delay after which self.testServer will send a response. // The delay after which self.testServer will send a response.
@property(atomic) NSTimeInterval serverResponseDelay; @property(atomic) NSTimeInterval serverResponseDelay;
;
@end @end
@implementation ReadingListTestCase @implementation ReadingListTestCase
...@@ -559,9 +492,8 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -559,9 +492,8 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
ReadingListModel* model = GetReadingListModel(); GREYAssertNil([ReadingListAppInterface clearEntries],
for (const GURL& url : model->Keys()) @"Unable to clear Reading List entries");
model->RemoveEntryByURL(url);
self.testServer->RegisterRequestHandler(base::BindRepeating( self.testServer->RegisterRequestHandler(base::BindRepeating(
&net::test_server::HandlePrefixedRequest, kDistillableURL, &net::test_server::HandlePrefixedRequest, kDistillableURL,
base::BindRepeating(&HandleQueryOrCloseSocket, base::BindRepeating(&HandleQueryOrCloseSocket,
...@@ -576,6 +508,11 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -576,6 +508,11 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start."); GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
} }
- (void)tearDown {
[super tearDown];
[ReadingListAppInterface resetConnectionType];
}
// Tests that the Reading List view is accessible. // Tests that the Reading List view is accessible.
- (void)testAccessibility { - (void)testAccessibility {
AddEntriesAndEnterEdit(); AddEntriesAndEnterEdit();
...@@ -589,14 +526,12 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -589,14 +526,12 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// appearing, and that the Reading List entry is present in the Reading List. // appearing, and that the Reading List entry is present in the Reading List.
// Loads offline version via context menu. // Loads offline version via context menu.
- (void)testSavingToReadingListAndLoadDistilled { - (void)testSavingToReadingListAndLoadDistilled {
auto network_change_disabler = [ReadingListAppInterface forceConnectionToWifi];
std::make_unique<net::NetworkChangeNotifier::DisableForTest>();
auto wifi_network = std::make_unique<WifiNetworkChangeNotifier>();
GURL distillablePageURL(self.testServer->GetURL(kDistillableURL)); GURL distillablePageURL(self.testServer->GetURL(kDistillableURL));
GURL nonDistillablePageURL(self.testServer->GetURL(kNonDistillableURL)); GURL nonDistillablePageURL(self.testServer->GetURL(kNonDistillableURL));
std::string pageTitle(kDistillableTitle);
// Open http://potato // Open http://potato
[ChromeEarlGrey loadURL:distillablePageURL]; [ChromeEarlGrey loadURL:distillablePageURL];
[ChromeEarlGrey waitForPageToFinishLoading];
AddCurrentPageToReadingList(); AddCurrentPageToReadingList();
...@@ -606,14 +541,17 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -606,14 +541,17 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// Verify that an entry with the correct title is present in the reading list. // Verify that an entry with the correct title is present in the reading list.
OpenReadingList(); OpenReadingList();
AssertEntryVisible(pageTitle); AssertEntryVisible(kDistillableTitle);
WaitForDistillation(); WaitForDistillation();
// Long press the entry, and open it offline. // Long press the entry, and open it offline.
LongPressEntry(pageTitle); LongPressEntry(kDistillableTitle);
TapContextMenuButtonWithA11yLabelID( TapContextMenuButtonWithA11yLabelID(
IDS_IOS_READING_LIST_CONTENT_CONTEXT_OFFLINE); IDS_IOS_READING_LIST_CONTENT_CONTEXT_OFFLINE);
[ChromeEarlGrey waitForPageToFinishLoading];
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(1));
AssertIsShowingDistillablePage(false, distillablePageURL); AssertIsShowingDistillablePage(false, distillablePageURL);
// Tap the Omnibox' Info Bubble to open the Page Info. // Tap the Omnibox' Info Bubble to open the Page Info.
...@@ -626,18 +564,15 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -626,18 +564,15 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// Verify that the webState's title is correct. // Verify that the webState's title is correct.
XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == GREYAssertEqualObjects([ChromeEarlGreyAppInterface currentTabTitle],
base::ASCIIToUTF16(pageTitle.c_str())); kDistillableTitle, @"Wrong page name");
} }
// Tests that sharing a web page to the Reading List results in a snackbar // Tests that sharing a web page to the Reading List results in a snackbar
// appearing, and that the Reading List entry is present in the Reading List. // appearing, and that the Reading List entry is present in the Reading List.
// Loads online version by tapping on entry. // Loads online version by tapping on entry.
- (void)testSavingToReadingListAndLoadNormal { - (void)testSavingToReadingListAndLoadNormal {
auto network_change_disabler = [ReadingListAppInterface forceConnectionToWifi];
std::make_unique<net::NetworkChangeNotifier::DisableForTest>();
auto wifi_network = std::make_unique<WifiNetworkChangeNotifier>();
std::string pageTitle(kDistillableTitle);
GURL distillableURL = self.testServer->GetURL(kDistillableURL); GURL distillableURL = self.testServer->GetURL(kDistillableURL);
// Open http://potato // Open http://potato
[ChromeEarlGrey loadURL:distillableURL]; [ChromeEarlGrey loadURL:distillableURL];
...@@ -650,11 +585,11 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -650,11 +585,11 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// Verify that an entry with the correct title is present in the reading list. // Verify that an entry with the correct title is present in the reading list.
OpenReadingList(); OpenReadingList();
AssertEntryVisible(pageTitle); AssertEntryVisible(kDistillableTitle);
WaitForDistillation(); WaitForDistillation();
// Press the entry, and open it online. // Press the entry, and open it online.
TapEntry(pageTitle); TapEntry(kDistillableTitle);
AssertIsShowingDistillablePage(true, distillableURL); AssertIsShowingDistillablePage(true, distillableURL);
// Stop server to reload offline. // Stop server to reload offline.
...@@ -662,8 +597,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -662,8 +597,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
base::test::ios::SpinRunLoopWithMinDelay( base::test::ios::SpinRunLoopWithMinDelay(
base::TimeDelta::FromSecondsD(kServerOperationDelay)); base::TimeDelta::FromSecondsD(kServerOperationDelay));
chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( [ChromeEarlGreyAppInterface startReloading];
web::ReloadType::NORMAL, false);
AssertIsShowingDistillablePage(false, distillableURL); AssertIsShowingDistillablePage(false, distillableURL);
} }
...@@ -671,10 +605,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -671,10 +605,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// appearing, and that the Reading List entry is present in the Reading List. // appearing, and that the Reading List entry is present in the Reading List.
// Loads offline version by tapping on entry without web server. // Loads offline version by tapping on entry without web server.
- (void)testSavingToReadingListAndLoadNoNetwork { - (void)testSavingToReadingListAndLoadNoNetwork {
auto network_change_disabler = [ReadingListAppInterface forceConnectionToWifi];
std::make_unique<net::NetworkChangeNotifier::DisableForTest>();
auto wifi_network = std::make_unique<WifiNetworkChangeNotifier>();
std::string pageTitle(kDistillableTitle);
GURL distillableURL = self.testServer->GetURL(kDistillableURL); GURL distillableURL = self.testServer->GetURL(kDistillableURL);
// Open http://potato // Open http://potato
[ChromeEarlGrey loadURL:distillableURL]; [ChromeEarlGrey loadURL:distillableURL];
...@@ -688,7 +619,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -688,7 +619,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// Verify that an entry with the correct title is present in the reading list. // Verify that an entry with the correct title is present in the reading list.
OpenReadingList(); OpenReadingList();
AssertEntryVisible(pageTitle); AssertEntryVisible(kDistillableTitle);
WaitForDistillation(); WaitForDistillation();
// Stop server to generate error. // Stop server to generate error.
...@@ -696,12 +627,11 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -696,12 +627,11 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
base::test::ios::SpinRunLoopWithMinDelay( base::test::ios::SpinRunLoopWithMinDelay(
base::TimeDelta::FromSecondsD(kServerOperationDelay)); base::TimeDelta::FromSecondsD(kServerOperationDelay));
// Long press the entry, and open it offline. // Long press the entry, and open it offline.
TapEntry(pageTitle); TapEntry(kDistillableTitle);
AssertIsShowingDistillablePage(false, distillableURL); AssertIsShowingDistillablePage(false, distillableURL);
// Reload. As server is still down, the offline page should show again. // Reload. As server is still down, the offline page should show again.
chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( [ChromeEarlGreyAppInterface startReloading];
web::ReloadType::NORMAL, false);
AssertIsShowingDistillablePage(false, distillableURL); AssertIsShowingDistillablePage(false, distillableURL);
// TODO(crbug.com/954248) This DCHECK's (but works) with slimnav disabled. // TODO(crbug.com/954248) This DCHECK's (but works) with slimnav disabled.
...@@ -716,8 +646,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -716,8 +646,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
base::test::ios::SpinRunLoopWithMinDelay( base::test::ios::SpinRunLoopWithMinDelay(
base::TimeDelta::FromSecondsD(kServerOperationDelay)); base::TimeDelta::FromSecondsD(kServerOperationDelay));
chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( [ChromeEarlGreyAppInterface startReloading];
web::ReloadType::NORMAL, false);
AssertIsShowingDistillablePage(true, distillableURL); AssertIsShowingDistillablePage(true, distillableURL);
} }
...@@ -725,10 +654,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -725,10 +654,7 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// appearing, and that the Reading List entry is present in the Reading List. // appearing, and that the Reading List entry is present in the Reading List.
// Loads offline version by tapping on entry with delayed web server. // Loads offline version by tapping on entry with delayed web server.
- (void)testSavingToReadingListAndLoadBadNetwork { - (void)testSavingToReadingListAndLoadBadNetwork {
auto network_change_disabler = [ReadingListAppInterface forceConnectionToWifi];
std::make_unique<net::NetworkChangeNotifier::DisableForTest>();
auto wifi_network = std::make_unique<WifiNetworkChangeNotifier>();
std::string pageTitle(kDistillableTitle);
GURL distillableURL = self.testServer->GetURL(kDistillableURL); GURL distillableURL = self.testServer->GetURL(kDistillableURL);
// Open http://potato // Open http://potato
[ChromeEarlGrey loadURL:distillableURL]; [ChromeEarlGrey loadURL:distillableURL];
...@@ -741,33 +667,35 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -741,33 +667,35 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
// Verify that an entry with the correct title is present in the reading // Verify that an entry with the correct title is present in the reading
OpenReadingList(); OpenReadingList();
AssertEntryVisible(pageTitle); AssertEntryVisible(kDistillableTitle);
WaitForDistillation(); WaitForDistillation();
self.serverResponseDelay = kDelayForSlowWebServer; self.serverResponseDelay = kDelayForSlowWebServer;
// Open the entry. // Open the entry.
TapEntry(pageTitle); TapEntry(kDistillableTitle);
AssertIsShowingDistillablePage(false, distillableURL); AssertIsShowingDistillablePage(false, distillableURL);
[ChromeEarlGrey goBack]; [ChromeEarlGrey goBack];
[ChromeEarlGrey goForward]; [ChromeEarlGrey goForward];
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(1));
AssertIsShowingDistillablePage(false, distillableURL); AssertIsShowingDistillablePage(false, distillableURL);
// Reload should load online page. // Reload should load online page.
chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( [ChromeEarlGreyAppInterface startReloading];
web::ReloadType::NORMAL, false);
AssertIsShowingDistillablePage(true, distillableURL); AssertIsShowingDistillablePage(true, distillableURL);
// Reload should load offline page. // Reload should load offline page.
chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( [ChromeEarlGreyAppInterface startReloading];
web::ReloadType::NORMAL, false);
AssertIsShowingDistillablePage(false, distillableURL); AssertIsShowingDistillablePage(false, distillableURL);
} }
// Tests that only the "Edit" button is showing when not editing. // Tests that only the "Edit" button is showing when not editing.
- (void)testVisibleButtonsNonEditingMode { - (void)testVisibleButtonsNonEditingMode {
GetReadingListModel()->AddEntry(GURL(kUnreadURL), std::string(kUnreadTitle), GREYAssertNil(
reading_list::ADDED_VIA_CURRENT_APP); [ReadingListAppInterface addEntryWithURL:[NSURL URLWithString:kUnreadURL]
title:kUnreadTitle
read:NO],
@"Unable to add Reading List entry.");
OpenReadingList(); OpenReadingList();
AssertToolbarButtonNotVisibleWithID(kReadingListToolbarDeleteButtonID); AssertToolbarButtonNotVisibleWithID(kReadingListToolbarDeleteButtonID);
...@@ -840,8 +768,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -840,8 +768,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
AssertEntryNotVisible(kReadTitle2); AssertEntryNotVisible(kReadTitle2);
AssertEntryVisible(kUnreadTitle); AssertEntryVisible(kUnreadTitle);
AssertEntryVisible(kUnreadTitle2); AssertEntryVisible(kUnreadTitle2);
XCTAssertEqual(kNumberReadEntries - 1, ModelReadSize(GetReadingListModel())); XCTAssertEqual([ReadingListAppInterface readEntriesCount],
XCTAssertEqual(kNumberUnreadEntries, GetReadingListModel()->unread_size()); static_cast<long>(kNumberReadEntries - 1));
XCTAssertEqual([ReadingListAppInterface unreadEntriesCount],
kNumberUnreadEntries);
} }
// Tests the deletion of all read entries. // Tests the deletion of all read entries.
...@@ -855,8 +785,9 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -855,8 +785,9 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
AssertHeaderNotVisible(kReadHeader); AssertHeaderNotVisible(kReadHeader);
AssertEntryVisible(kUnreadTitle); AssertEntryVisible(kUnreadTitle);
AssertEntryVisible(kUnreadTitle2); AssertEntryVisible(kUnreadTitle2);
XCTAssertEqual((size_t)0, ModelReadSize(GetReadingListModel())); XCTAssertEqual(0l, [ReadingListAppInterface readEntriesCount]);
XCTAssertEqual(kNumberUnreadEntries, GetReadingListModel()->unread_size()); XCTAssertEqual(kNumberUnreadEntries,
[ReadingListAppInterface unreadEntriesCount]);
} }
// Marks all unread entries as read. // Marks all unread entries as read.
...@@ -872,9 +803,9 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -872,9 +803,9 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
AssertHeaderNotVisible(kUnreadHeader); AssertHeaderNotVisible(kUnreadHeader);
AssertAllEntriesVisible(); AssertAllEntriesVisible();
XCTAssertEqual(kNumberUnreadEntries + kNumberReadEntries, XCTAssertEqual(static_cast<long>(kNumberUnreadEntries + kNumberReadEntries),
ModelReadSize(GetReadingListModel())); [ReadingListAppInterface readEntriesCount]);
XCTAssertEqual((size_t)0, GetReadingListModel()->unread_size()); XCTAssertEqual(0l, [ReadingListAppInterface unreadEntriesCount]);
} }
// Marks all read entries as unread. // Marks all read entries as unread.
...@@ -890,9 +821,9 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -890,9 +821,9 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
AssertHeaderNotVisible(kReadHeader); AssertHeaderNotVisible(kReadHeader);
AssertAllEntriesVisible(); AssertAllEntriesVisible();
XCTAssertEqual(kNumberUnreadEntries + kNumberReadEntries, XCTAssertEqual(static_cast<long>(kNumberUnreadEntries + kNumberReadEntries),
GetReadingListModel()->unread_size()); [ReadingListAppInterface unreadEntriesCount]);
XCTAssertEqual((size_t)0, ModelReadSize(GetReadingListModel())); XCTAssertEqual(0l, [ReadingListAppInterface readEntriesCount]);
} }
// Marks all read entries as unread, when there is a lot of entries. This is to // Marks all read entries as unread, when there is a lot of entries. This is to
...@@ -919,9 +850,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -919,9 +850,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
TapToolbarButtonWithID(kReadingListToolbarMarkButtonID); TapToolbarButtonWithID(kReadingListToolbarMarkButtonID);
AssertAllEntriesVisible(); AssertAllEntriesVisible();
XCTAssertEqual(kNumberReadEntries + 1, ModelReadSize(GetReadingListModel())); XCTAssertEqual(static_cast<long>(kNumberReadEntries + 1),
XCTAssertEqual(kNumberUnreadEntries - 1, [ReadingListAppInterface readEntriesCount]);
GetReadingListModel()->unread_size()); XCTAssertEqual(static_cast<long>(kNumberUnreadEntries - 1),
[ReadingListAppInterface unreadEntriesCount]);
} }
// Selects an read entry and mark it as unread. // Selects an read entry and mark it as unread.
...@@ -933,9 +865,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -933,9 +865,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
TapToolbarButtonWithID(kReadingListToolbarMarkButtonID); TapToolbarButtonWithID(kReadingListToolbarMarkButtonID);
AssertAllEntriesVisible(); AssertAllEntriesVisible();
XCTAssertEqual(kNumberReadEntries - 1, ModelReadSize(GetReadingListModel())); XCTAssertEqual(static_cast<long>(kNumberReadEntries - 1),
XCTAssertEqual(kNumberUnreadEntries + 1, [ReadingListAppInterface readEntriesCount]);
GetReadingListModel()->unread_size()); XCTAssertEqual(static_cast<long>(kNumberUnreadEntries + 1),
[ReadingListAppInterface unreadEntriesCount]);
} }
// Selects read and unread entries and mark them as unread. // Selects read and unread entries and mark them as unread.
...@@ -951,9 +884,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -951,9 +884,10 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
TapContextMenuButtonWithA11yLabelID(IDS_IOS_READING_LIST_MARK_UNREAD_BUTTON); TapContextMenuButtonWithA11yLabelID(IDS_IOS_READING_LIST_MARK_UNREAD_BUTTON);
AssertAllEntriesVisible(); AssertAllEntriesVisible();
XCTAssertEqual(kNumberReadEntries - 1, ModelReadSize(GetReadingListModel())); XCTAssertEqual(static_cast<long>(kNumberReadEntries - 1),
XCTAssertEqual(kNumberUnreadEntries + 1, [ReadingListAppInterface readEntriesCount]);
GetReadingListModel()->unread_size()); XCTAssertEqual(static_cast<long>(kNumberUnreadEntries + 1),
[ReadingListAppInterface unreadEntriesCount]);
} }
// Selects read and unread entries and mark them as read. // Selects read and unread entries and mark them as read.
...@@ -969,22 +903,24 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -969,22 +903,24 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
TapContextMenuButtonWithA11yLabelID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); TapContextMenuButtonWithA11yLabelID(IDS_IOS_READING_LIST_MARK_READ_BUTTON);
AssertAllEntriesVisible(); AssertAllEntriesVisible();
XCTAssertEqual(kNumberReadEntries + 1, ModelReadSize(GetReadingListModel())); XCTAssertEqual(static_cast<long>(kNumberReadEntries + 1),
XCTAssertEqual(kNumberUnreadEntries - 1, [ReadingListAppInterface readEntriesCount]);
GetReadingListModel()->unread_size()); XCTAssertEqual(static_cast<long>(kNumberUnreadEntries - 1),
[ReadingListAppInterface unreadEntriesCount]);
} }
// Tests that you can delete multiple read items in the Reading List without // Tests that you can delete multiple read items in the Reading List without
// creating a crash (crbug.com/701956). // creating a crash (crbug.com/701956).
- (void)testDeleteMultipleItems { - (void)testDeleteMultipleItems {
// Add entries. // Add entries.
ReadingListModel* model = GetReadingListModel();
for (int i = 0; i < 11; i++) { for (int i = 0; i < 11; i++) {
std::string increment = std::to_string(i); NSURL* url =
model->AddEntry(GURL(kReadURL + increment), [NSURL URLWithString:[kReadURL stringByAppendingFormat:@"%d", i]];
std::string(kReadTitle + increment), NSString* title = [kReadURL stringByAppendingFormat:@"%d", i];
reading_list::ADDED_VIA_CURRENT_APP); GREYAssertNil([ReadingListAppInterface addEntryWithURL:url
model->SetReadStatus(GURL(kReadURL + increment), true); title:title
read:YES],
@"Unable to add Reading List entry.");
} }
// Delete them from the Reading List view. // Delete them from the Reading List view.
...@@ -1004,30 +940,27 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) { ...@@ -1004,30 +940,27 @@ void AssertIsShowingDistillablePage(bool online, const GURL& distillable_url) {
if (!base::ios::IsRunningOnOrLater(13, 0, 0)) { if (!base::ios::IsRunningOnOrLater(13, 0, 0)) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on iOS 12 and lower."); EARL_GREY_TEST_SKIPPED(@"Test disabled on iOS 12 and lower.");
} }
if (!IsCollectionsCardPresentationStyleEnabled()) { if (![ChromeEarlGreyAppInterface isCollectionsCardPresentationStyleEnabled]) {
EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off."); EARL_GREY_TEST_SKIPPED(@"Test disabled on when feature flag is off.");
} }
GetReadingListModel()->AddEntry(GURL(kUnreadURL), std::string(kUnreadTitle), GREYAssertNil(
reading_list::ADDED_VIA_CURRENT_APP); [ReadingListAppInterface addEntryWithURL:[NSURL URLWithString:kUnreadURL]
title:kUnreadTitle
read:NO],
@"Unable to add Reading List entry.");
OpenReadingList(); OpenReadingList();
// Check that the TableView is presented. // Check that the TableView is presented.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kReadingListViewID)]
[[ReadingListTableViewController
class] accessibilityIdentifier])]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// Swipe TableView down. // Swipe TableView down.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kReadingListViewID)]
[[ReadingListTableViewController
class] accessibilityIdentifier])]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
// Check that the TableView has been dismissed. // Check that the TableView has been dismissed.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID( [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kReadingListViewID)]
[[ReadingListTableViewController
class] accessibilityIdentifier])]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h" #import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#import "ios/chrome/browser/ui/reading_list/empty_reading_list_message_util.h" #import "ios/chrome/browser/ui/reading_list/empty_reading_list_message_util.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_constants.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_data_sink.h" #import "ios/chrome/browser/ui/reading_list/reading_list_data_sink.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_data_source.h" #import "ios/chrome/browser/ui/reading_list/reading_list_data_source.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_list_item_updater.h" #import "ios/chrome/browser/ui/reading_list/reading_list_list_item_updater.h"
...@@ -189,7 +190,7 @@ ReadingListSelectionState GetSelectionStateForSelectedCounts( ...@@ -189,7 +190,7 @@ ReadingListSelectionState GetSelectionStateForSelectedCounts(
} }
+ (NSString*)accessibilityIdentifier { + (NSString*)accessibilityIdentifier {
return @"ReadingListTableView"; return kReadingListViewID;
} }
#pragma mark - UIViewController #pragma mark - UIViewController
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "base/logging.h" #include "base/logging.h"
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_constants.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button_commands.h" #import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button_commands.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_toolbar_button_identifiers.h"
#import "ios/chrome/common/colors/semantic_color_names.h" #import "ios/chrome/common/colors/semantic_color_names.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
......
...@@ -34,6 +34,8 @@ source_set("table_view") { ...@@ -34,6 +34,8 @@ source_set("table_view") {
source_set("constants") { source_set("constants") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"table_view_constants.h",
"table_view_constants.mm",
"table_view_navigation_controller_constants.h", "table_view_navigation_controller_constants.h",
"table_view_navigation_controller_constants.mm", "table_view_navigation_controller_constants.mm",
] ]
...@@ -78,6 +80,7 @@ source_set("views") { ...@@ -78,6 +80,7 @@ source_set("views") {
"table_view_loading_view.mm", "table_view_loading_view.mm",
] ]
deps = [ deps = [
":constants",
"//base", "//base",
"//ios/chrome/browser/ui/colors", "//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/material_components", "//ios/chrome/browser/ui/material_components",
......
...@@ -54,6 +54,7 @@ source_set("cells") { ...@@ -54,6 +54,7 @@ source_set("cells") {
"//ios/chrome/browser/ui/colors:colors", "//ios/chrome/browser/ui/colors:colors",
"//ios/chrome/browser/ui/elements", "//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/list_model", "//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/reading_list:reading_list_constants",
"//ios/chrome/browser/ui/settings/cells:public", "//ios/chrome/browser/ui/settings/cells:public",
"//ios/chrome/browser/ui/table_view:styler", "//ios/chrome/browser/ui/table_view:styler",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_url_cell_favicon_badge_view.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_url_cell_favicon_badge_view.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
...@@ -21,7 +23,7 @@ ...@@ -21,7 +23,7 @@
#pragma mark - Public #pragma mark - Public
+ (NSString*)accessibilityIdentifier { + (NSString*)accessibilityIdentifier {
return @"TableViewURLCellFaviconBadgeView"; return kTableViewURLCellFaviconBadgeViewID;
} }
#pragma mark - UIImageView #pragma mark - UIImageView
......
// Copyright 2019 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.
#ifndef IOS_CHROME_BROWSER_UI_TABLE_VIEW_TABLE_VIEW_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_TABLE_VIEW_TABLE_VIEW_CONSTANTS_H_
#import <Foundation/Foundation.h>
extern NSString* const kTableViewEmptyViewID;
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_TABLE_VIEW_CONSTANTS_H_
// Copyright 2019 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 "ios/chrome/browser/ui/table_view/table_view_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* const kTableViewEmptyViewID = @"TableViewEmptyView";
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/table_view/table_view_empty_view.h" #import "ios/chrome/browser/ui/table_view/table_view_empty_view.h"
#import "ios/chrome/browser/ui/table_view/table_view_constants.h"
#import "ios/chrome/common/colors/semantic_color_names.h" #import "ios/chrome/common/colors/semantic_color_names.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -84,7 +85,7 @@ NSAttributedString* GetAttributedMessage(NSString* message) { ...@@ -84,7 +85,7 @@ NSAttributedString* GetAttributedMessage(NSString* message) {
#pragma mark - Public #pragma mark - Public
+ (NSString*)accessibilityIdentifier { + (NSString*)accessibilityIdentifier {
return @"TableViewEmptyView"; return kTableViewEmptyViewID;
} }
- (void)setScrollViewContentInsets:(UIEdgeInsets)scrollViewContentInsets { - (void)setScrollViewContentInsets:(UIEdgeInsets)scrollViewContentInsets {
......
...@@ -272,6 +272,7 @@ source_set("test_support") { ...@@ -272,6 +272,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/static_content", "//ios/chrome/browser/ui/static_content",
"//ios/chrome/browser/ui/tab_grid:tab_grid_ui_constants", "//ios/chrome/browser/ui/tab_grid:tab_grid_ui_constants",
"//ios/chrome/browser/ui/tab_grid/grid:grid_ui_constants", "//ios/chrome/browser/ui/tab_grid/grid:grid_ui_constants",
"//ios/chrome/browser/ui/table_view:feature_flags",
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/ui/toolbar:test_support", "//ios/chrome/browser/ui/toolbar:test_support",
"//ios/chrome/browser/ui/toolbar:toolbar_ui", "//ios/chrome/browser/ui/toolbar:toolbar_ui",
...@@ -385,6 +386,7 @@ source_set("eg_app_support+eg2") { ...@@ -385,6 +386,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/payments:payments_ui", "//ios/chrome/browser/ui/payments:payments_ui",
"//ios/chrome/browser/ui/popup_menu:constants", "//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/qr_scanner:eg_app_support+eg2", "//ios/chrome/browser/ui/qr_scanner:eg_app_support+eg2",
"//ios/chrome/browser/ui/reading_list:eg_app_support+eg2",
"//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui_constants", "//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui_constants",
"//ios/chrome/browser/ui/safe_mode", "//ios/chrome/browser/ui/safe_mode",
"//ios/chrome/browser/ui/safe_mode:eg_app_support+eg2", "//ios/chrome/browser/ui/safe_mode:eg_app_support+eg2",
...@@ -403,6 +405,7 @@ source_set("eg_app_support+eg2") { ...@@ -403,6 +405,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/static_content", "//ios/chrome/browser/ui/static_content",
"//ios/chrome/browser/ui/tab_grid:tab_grid_ui_constants", "//ios/chrome/browser/ui/tab_grid:tab_grid_ui_constants",
"//ios/chrome/browser/ui/tab_grid/grid:grid_ui_constants", "//ios/chrome/browser/ui/tab_grid/grid:grid_ui_constants",
"//ios/chrome/browser/ui/table_view:feature_flags",
"//ios/chrome/browser/ui/toolbar:eg_app_support+eg2", "//ios/chrome/browser/ui/toolbar:eg_app_support+eg2",
"//ios/chrome/browser/ui/toolbar:toolbar_ui", "//ios/chrome/browser/ui/toolbar:toolbar_ui",
"//ios/chrome/browser/ui/toolbar/keyboard_assist", "//ios/chrome/browser/ui/toolbar/keyboard_assist",
......
...@@ -37,6 +37,12 @@ ...@@ -37,6 +37,12 @@
// web state. // web state.
+ (id<GREYAction>)tapWebElement:(ElementSelector*)selector; + (id<GREYAction>)tapWebElement:(ElementSelector*)selector;
// Action to scroll to top of a collection.
// On iOS 13 the settings menu appears as a card that can be dismissed with a
// downward swipe, for this reason we need to swipe up programatically to
// avoid dismissing the VC.
+ (id<GREYAction>)scrollToTop;
@end @end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_ACTIONS_APP_INTERFACE_H_ #endif // IOS_CHROME_TEST_EARL_GREY_CHROME_ACTIONS_APP_INTERFACE_H_
...@@ -105,4 +105,25 @@ NSString* kChromeActionsErrorDomain = @"ChromeActionsError"; ...@@ -105,4 +105,25 @@ NSString* kChromeActionsErrorDomain = @"ChromeActionsError";
selector); selector);
} }
+ (id<GREYAction>)scrollToTop {
GREYPerformBlock scrollToTopBlock = ^BOOL(id element,
__strong NSError** error) {
grey_dispatch_sync_on_main_thread(^{
UIScrollView* view = base::mac::ObjCCast<UIScrollView>(element);
if (!view) {
*error = [NSError
errorWithDomain:kChromeActionsErrorDomain
code:0
userInfo:@{
NSLocalizedDescriptionKey : @"View is not a UIScrollView"
}];
}
view.contentOffset = CGPointZero;
});
return YES;
};
return [GREYActionBlock actionWithName:@"Scroll to top"
performBlock:scrollToTopBlock];
}
@end @end
...@@ -343,6 +343,9 @@ ...@@ -343,6 +343,9 @@
// with custom WebKit frameworks. // with custom WebKit frameworks.
+ (BOOL)isCustomWebKitLoadedIfRequested WARN_UNUSED_RESULT; + (BOOL)isCustomWebKitLoadedIfRequested WARN_UNUSED_RESULT;
// Returns YES if collections are presented in cards.
+ (BOOL)isCollectionsCardPresentationStyleEnabled WARN_UNUSED_RESULT;
#pragma mark - Popup Blocking #pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the // Gets the current value of the popup content setting preference for the
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h" #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#import "ios/chrome/browser/ntp/features.h" #import "ios/chrome/browser/ntp/features.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h" #import "ios/chrome/browser/ui/settings/autofill/features.h"
#import "ios/chrome/browser/ui/table_view/feature_flags.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h" #import "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/ui/util/named_guide.h" #import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h" #import "ios/chrome/browser/web/tab_id_tab_helper.h"
...@@ -587,6 +588,10 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -587,6 +588,10 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
return IsCustomWebKitLoadedIfRequested(); return IsCustomWebKitLoadedIfRequested();
} }
+ (BOOL)isCollectionsCardPresentationStyleEnabled {
return IsCollectionsCardPresentationStyleEnabled();
}
#pragma mark - ScopedBlockPopupsPref #pragma mark - ScopedBlockPopupsPref
+ (ContentSetting)popupPrefValue { + (ContentSetting)popupPrefValue {
......
...@@ -288,6 +288,9 @@ id<GREYMatcher> PaymentRequestPickerRow(); ...@@ -288,6 +288,9 @@ id<GREYMatcher> PaymentRequestPickerRow();
// Returns matcher for the payment request search bar. // Returns matcher for the payment request search bar.
id<GREYMatcher> PaymentRequestPickerSearchBar(); id<GREYMatcher> PaymentRequestPickerSearchBar();
// Returns matcher for the reading list on the Tools menu.
id<GREYMatcher> ReadingListMenuButton();
// Returns matcher for the bookmarks button on the Tools menu. // Returns matcher for the bookmarks button on the Tools menu.
id<GREYMatcher> BookmarksMenuButton(); id<GREYMatcher> BookmarksMenuButton();
......
...@@ -363,6 +363,10 @@ id<GREYMatcher> PaymentRequestPickerSearchBar() { ...@@ -363,6 +363,10 @@ id<GREYMatcher> PaymentRequestPickerSearchBar() {
return [ChromeMatchersAppInterface paymentRequestPickerSearchBar]; return [ChromeMatchersAppInterface paymentRequestPickerSearchBar];
} }
id<GREYMatcher> ReadingListMenuButton() {
return [ChromeMatchersAppInterface readingListMenuButton];
}
id<GREYMatcher> BookmarksMenuButton() { id<GREYMatcher> BookmarksMenuButton() {
return [ChromeMatchersAppInterface bookmarksMenuButton]; return [ChromeMatchersAppInterface bookmarksMenuButton];
} }
......
...@@ -293,6 +293,9 @@ ...@@ -293,6 +293,9 @@
// Returns matcher for the payment request search bar. // Returns matcher for the payment request search bar.
+ (id<GREYMatcher>)paymentRequestPickerSearchBar; + (id<GREYMatcher>)paymentRequestPickerSearchBar;
// Returns matcher for the reading list button on the Tools menu.
+ (id<GREYMatcher>)readingListMenuButton;
// Returns matcher for the bookmarks button on the Tools menu. // Returns matcher for the bookmarks button on the Tools menu.
+ (id<GREYMatcher>)bookmarksMenuButton; + (id<GREYMatcher>)bookmarksMenuButton;
......
...@@ -620,6 +620,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -620,6 +620,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID); return grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID);
} }
+ (id<GREYMatcher>)readingListMenuButton {
return grey_accessibilityID(kToolsMenuReadingListId);
}
+ (id<GREYMatcher>)bookmarksMenuButton { + (id<GREYMatcher>)bookmarksMenuButton {
return grey_accessibilityID(kToolsMenuBookmarksId); return grey_accessibilityID(kToolsMenuBookmarksId);
} }
......
...@@ -80,6 +80,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") { ...@@ -80,6 +80,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
"//ios/chrome/browser/ui/page_info:eg2_tests", "//ios/chrome/browser/ui/page_info:eg2_tests",
"//ios/chrome/browser/ui/popup_menu:eg2_tests", "//ios/chrome/browser/ui/popup_menu:eg2_tests",
"//ios/chrome/browser/ui/qr_scanner:eg2_tests", "//ios/chrome/browser/ui/qr_scanner:eg2_tests",
"//ios/chrome/browser/ui/reading_list:eg2_tests",
"//ios/chrome/browser/ui/sad_tab:eg2_tests", "//ios/chrome/browser/ui/sad_tab:eg2_tests",
"//ios/chrome/browser/ui/safe_mode:eg2_tests", "//ios/chrome/browser/ui/safe_mode:eg2_tests",
"//ios/chrome/browser/ui/side_swipe:eg2_tests", "//ios/chrome/browser/ui/side_swipe:eg2_tests",
......
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