blob: 815b4d73561d208b6cce3c0eb738b216943ba56c [file] [log] [blame]
// 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 <Foundation/Foundation.h>
// Methods used by CWTRequestHandler to perform browser-level actions such as
// opening and closing tabs, navigating to a URL, and injecting JavaScript.
// These methods run on a background thread in the app process in order to
// avoid deadlock while waiting for actions to complete on the main thread.
@interface CWTWebDriverAppInterface : NSObject
// The background thread where this class' methods are run.
@property(nonatomic, readonly) dispatch_queue_t executingQueue;
// Loads the given URL in the tab identified by |tabID|. Returns an error if the
// page fails to load within |timeout| seconds or if no such tab exists.
+ (NSError*)loadURL:(NSString*)URL
// Returns the id of the current tab. If no tabs are open, returns nil.
+ (NSString*)currentTabID;
// Returns an array containing the ids of all open tabs.
+ (NSArray*)tabIDs;
// Closes the tab identified by |tabID|. Returns an error if there is no such
// tab.
+ (NSError*)closeTabWithID:(NSString*)ID;
// Opens a new tab, makes this tab the current tab, and return its id.
+ (NSString*)openNewTab;
// Makes the tab identified by |ID| the current tab. Returns an error if there
// is no such tab.
+ (NSError*)switchToTabWithID:(NSString*)ID;
// Executes the given JavaScript function in the tab identified by |tabID|. This
// must be a function that takes a single argument, and uses this argument as a
// completion handler. Returns the value passed to the completion handler. If
// no such tab exists, or if script execution does not complete within |timeout|
// seconds, returns nil.
+ (NSString*)executeAsyncJavaScriptFunction:(NSString*)function
// Allows script to open tabs using "" JavaScript calls.
+ (void)enablePopups;
// Takes a snapshot of the specified tab. Returns the snapshot as a base64-
// encoded image. If no such tab exists, returns nil.
+ (NSString*)takeSnapshotOfTabWithID:(NSString*)ID;
// Starts redirecting stderr output to the file with the given path.
+ (void)logStderrToFilePath:(NSString*)filePath;
// Stops redirecting stderr output to a file.
+ (void)stopLoggingStderr;
// Handles SIGABRT by exiting cleanly. This is used to catch abort() calls made
// by ASan, and prevent them from being detected as crashes by XCTest. When
// XCTest detects a crash, it terminates the test process. But CWTChromeDriver
// automatically re-launches the app after a crash during fuzzing, and XCTest's
// crash detection logic interferes with this.
+ (void)installCleanExitHandlerForAbortSignal;