OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.content_shell.browsertests; | 5 package org.chromium.content_shell.browsertests; |
6 | 6 |
7 import android.view.Window; | 7 import android.view.Window; |
8 import android.view.WindowManager; | 8 import android.view.WindowManager; |
9 | 9 |
10 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
11 import org.chromium.base.annotations.SuppressFBWarnings; | 11 import org.chromium.base.annotations.SuppressFBWarnings; |
12 import org.chromium.base.library_loader.LibraryLoader; | 12 import org.chromium.base.library_loader.LibraryLoader; |
13 import org.chromium.base.library_loader.LibraryProcessType; | 13 import org.chromium.base.library_loader.LibraryProcessType; |
14 import org.chromium.base.library_loader.ProcessInitException; | 14 import org.chromium.base.library_loader.ProcessInitException; |
15 import org.chromium.content.browser.BrowserStartupController; | 15 import org.chromium.content.browser.BrowserStartupController; |
16 import org.chromium.content_shell.ShellManager; | 16 import org.chromium.content_shell.ShellManager; |
17 import org.chromium.native_test.NativeBrowserTestActivity; | 17 import org.chromium.native_test.NativeBrowserTestActivity; |
18 import org.chromium.ui.base.ActivityWindowAndroid; | 18 import org.chromium.ui.base.ActivityWindowAndroid; |
19 import org.chromium.ui.base.WindowAndroid; | 19 import org.chromium.ui.base.WindowAndroid; |
20 | 20 |
21 import java.io.File; | |
22 | |
23 /** An Activity base class for running browser tests against ContentShell. */ | 21 /** An Activity base class for running browser tests against ContentShell. */ |
24 public abstract class ContentShellBrowserTestActivity extends NativeBrowserTestA
ctivity { | 22 public abstract class ContentShellBrowserTestActivity extends NativeBrowserTestA
ctivity { |
25 | 23 |
26 private static final String TAG = "cr.native_test"; | 24 private static final String TAG = "cr.native_test"; |
27 | 25 |
28 private ShellManager mShellManager; | 26 private ShellManager mShellManager; |
29 private WindowAndroid mWindowAndroid; | 27 private WindowAndroid mWindowAndroid; |
30 | 28 |
31 /** Deletes a file or directory along with any of its children. | 29 /** |
| 30 * Initializes the browser process. |
32 * | 31 * |
33 * Note that, like File.delete(), this returns false if the file or directo
ry couldn't be | 32 * This generally includes loading native libraries and switching to the nat
ive command line, |
34 * fully deleted. This means that, in the directory case, some files may be
deleted even if | 33 * among other things. |
35 * the entire directory couldn't be. | |
36 * | |
37 * @param file The file or directory to delete. | |
38 * @return Whether or not the file or directory was deleted. | |
39 */ | |
40 private static boolean deleteRecursive(File file) { | |
41 if (file == null) return true; | |
42 | |
43 File[] children = file.listFiles(); | |
44 if (children != null) { | |
45 for (File child : children) { | |
46 if (!deleteRecursive(child)) { | |
47 return false; | |
48 } | |
49 } | |
50 } | |
51 return file.delete(); | |
52 } | |
53 | |
54 /** Initializes the browser process. | |
55 * | |
56 * This generally includes loading native libraries and switching to the na
tive command line, | |
57 * among other things. | |
58 * | |
59 * @param privateDataDirectory The private data directory to clear before s
tarting the | |
60 * browser process. Can be null. | |
61 * @throws ProcessInitException if the native libraries cannot be loaded. | |
62 */ | 34 */ |
63 @Override | 35 @Override |
64 @SuppressFBWarnings("DM_EXIT") | 36 @SuppressFBWarnings("DM_EXIT") |
65 protected void initializeBrowserProcess() { | 37 protected void initializeBrowserProcess() { |
66 try { | 38 try { |
67 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER) | 39 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitiali
zed(); |
68 .ensureInitialized(getApplicationContext()); | |
69 } catch (ProcessInitException e) { | 40 } catch (ProcessInitException e) { |
70 Log.e(TAG, "Cannot load content_browsertests.", e); | 41 Log.e(TAG, "Cannot load content_browsertests.", e); |
71 System.exit(-1); | 42 System.exit(-1); |
72 } | 43 } |
73 BrowserStartupController.get(getApplicationContext(), LibraryProcessType
.PROCESS_BROWSER) | 44 BrowserStartupController.get(getApplicationContext(), LibraryProcessType
.PROCESS_BROWSER) |
74 .initChromiumBrowserProcessForTests(); | 45 .initChromiumBrowserProcessForTests(); |
75 | 46 |
76 setContentView(getTestActivityViewId()); | 47 setContentView(getTestActivityViewId()); |
77 mShellManager = (ShellManager) findViewById(getShellManagerViewId()); | 48 mShellManager = (ShellManager) findViewById(getShellManagerViewId()); |
78 mWindowAndroid = new ActivityWindowAndroid(this); | 49 mWindowAndroid = new ActivityWindowAndroid(this); |
79 mShellManager.setWindow(mWindowAndroid); | 50 mShellManager.setWindow(mWindowAndroid); |
80 | 51 |
81 Window wind = this.getWindow(); | 52 Window wind = this.getWindow(); |
82 wind.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); | 53 wind.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); |
83 wind.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); | 54 wind.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); |
84 wind.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); | 55 wind.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); |
85 } | 56 } |
86 | 57 |
87 protected abstract int getTestActivityViewId(); | 58 protected abstract int getTestActivityViewId(); |
88 | 59 |
89 protected abstract int getShellManagerViewId(); | 60 protected abstract int getShellManagerViewId(); |
90 } | 61 } |
OLD | NEW |