1 2 // Copyright 2016 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #ifndef IOS_CHROME_TEST_APP_CHROME_TEST_UTIL_H_ 7 #define IOS_CHROME_TEST_APP_CHROME_TEST_UTIL_H_ 8 9 #include "base/compiler_specific.h" 10 #import "base/ios/block_types.h" 11 #import "ios/chrome/browser/ui/commands/browser_commands.h" 12 13 @protocol ApplicationCommands; 14 class ChromeBrowserState; 15 @class MainController; 16 @class NewTabPageController; 17 @class SceneController; 18 @class SceneState; 19 @class UIViewController; 20 21 namespace chrome_test_util { 22 23 // Returns the main controller. 24 MainController* GetMainController(); 25 26 // Returns the foreground, active scene. 27 SceneState* GetForegroundActiveScene(); 28 29 // Returns the foreground, active scene controller. 30 SceneController* GetForegroundActiveSceneController(); 31 32 // Returns the number of regular Browsers for the default profile. 33 NSUInteger RegularBrowserCount(); 34 35 // Returns the current, non-incognito ChromeBrowserState. 36 ChromeBrowserState* GetOriginalBrowserState(); 37 38 // Returns the current incognito ChromeBrowserState 39 ChromeBrowserState* GetCurrentIncognitoBrowserState(); 40 41 // Returns the dispatcher for the main BVC. 42 // TODO(crbug.com/738881): Use HandlerForActiveBrowser() 43 // instead. 44 id<BrowserCommands> BrowserCommandDispatcherForMainBVC(); 45 46 // Returns the active view controller. 47 // NOTE: It is preferred to not directly access the active view controller if 48 // possible. 49 UIViewController* GetActiveViewController(); 50 51 // Returns the dispatcher for the active Browser. 52 id<ApplicationCommands, BrowserCommands> HandlerForActiveBrowser(); 53 54 // Removes all presented infobars. 55 void RemoveAllInfoBars(); 56 57 // Dismisses all presented views and modal dialogs. 58 void ClearPresentedState(); 59 60 // Sets the value of a boolean local state pref. 61 // TODO(crbug.com/647022): Clean up other tests that use this helper function. 62 void SetBooleanLocalStatePref(const char* pref_name, bool value); 63 64 // Sets the value of a boolean user pref in the given browser state. 65 void SetBooleanUserPref(ChromeBrowserState* browser_state, 66 const char* pref_name, 67 bool value); 68 69 // Sets the state of using cellular network. 70 void SetWWANStateTo(bool value); 71 72 // Sets the state of first launch. 73 void SetFirstLaunchStateTo(bool value); 74 75 // Checks whether metrics recording is enabled or not. 76 bool IsMetricsRecordingEnabled(); 77 78 // Checks whether metrics reporting is enabled or not. 79 bool IsMetricsReportingEnabled(); 80 81 // Checks whether breakpad recording is enabled or not. 82 bool IsBreakpadEnabled(); 83 84 // Checks whether breakpad reporting is enabled or not. 85 bool IsBreakpadReportingEnabled(); 86 87 // Checks whether this is the first launch after upgrade or not. 88 bool IsFirstLaunchAfterUpgrade(); 89 90 // Waits for Breakpad to process the queued updates. 91 void WaitForBreakpadQueue(); 92 93 // Simulates launching Chrome from another application. 94 void OpenChromeFromExternalApp(const GURL& url); 95 96 // Purges cached web view page, so the next time back navigation will not use 97 // cached page. Browsers don't have to use fresh version for back forward 98 // navigation for HTTP pages and may serve version from the cache even if 99 // Cache-Control response header says otherwise. 100 bool PurgeCachedWebViewPages() WARN_UNUSED_RESULT; 101 102 } // namespace chrome_test_util 103 104 #endif // IOS_CHROME_TEST_APP_CHROME_TEST_UTIL_H_ 105