Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.offlinepages; | 5 package org.chromium.chrome.browser.offlinepages; |
| 6 | 6 |
| 7 import android.app.NotificationManager; | 7 import android.app.NotificationManager; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.os.Environment; | 9 import android.os.Environment; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 private static final String TAG = "OPSPLEvaluation"; | 75 private static final String TAG = "OPSPLEvaluation"; |
| 76 private static final String NAMESPACE = "async_loading"; | 76 private static final String NAMESPACE = "async_loading"; |
| 77 private static final String NEW_LINE = System.getProperty("line.separator"); | 77 private static final String NEW_LINE = System.getProperty("line.separator"); |
| 78 private static final String DELIMITER = ";"; | 78 private static final String DELIMITER = ";"; |
| 79 private static final String CONFIG_FILE_PATH = "paquete/test_config"; | 79 private static final String CONFIG_FILE_PATH = "paquete/test_config"; |
| 80 private static final String INPUT_FILE_PATH = "paquete/offline_eval_urls.txt "; | 80 private static final String INPUT_FILE_PATH = "paquete/offline_eval_urls.txt "; |
| 81 private static final String LOG_OUTPUT_FILE_PATH = "paquete/offline_eval_log s.txt"; | 81 private static final String LOG_OUTPUT_FILE_PATH = "paquete/offline_eval_log s.txt"; |
| 82 private static final String RESULT_OUTPUT_FILE_PATH = "paquete/offline_eval_ results.txt"; | 82 private static final String RESULT_OUTPUT_FILE_PATH = "paquete/offline_eval_ results.txt"; |
| 83 private static final int GET_PAGES_TIMEOUT_MS = 5000; | 83 private static final int GET_PAGES_TIMEOUT_MS = 5000; |
| 84 private static final int PAGE_MODEL_LOAD_TIMEOUT_MS = 5000; | 84 private static final int PAGE_MODEL_LOAD_TIMEOUT_MS = 5000; |
| 85 private static final int REMOVE_REQUESTS_TIMEOUT_MS = 5000; | |
|
Pete Williamson
2016/11/07 23:45:26
Maybe allow a longer timeout. A svelte device mig
romax
2016/11/08 00:18:35
Done.
I've also updated the timeouts above.
| |
| 85 | 86 |
| 86 private OfflinePageEvaluationBridge mBridge; | 87 private OfflinePageEvaluationBridge mBridge; |
| 87 private OfflinePageEvaluationObserver mObserver; | 88 private OfflinePageEvaluationObserver mObserver; |
| 88 | 89 |
| 89 private Semaphore mDoneSemaphore; | 90 private Semaphore mDoneSemaphore; |
| 90 private List<String> mUrls; | 91 private List<String> mUrls; |
| 91 private int mCount; | 92 private int mCount; |
| 92 private boolean mIsUserRequested; | 93 private boolean mIsUserRequested; |
| 93 private boolean mUseTestScheduler; | 94 private boolean mUseTestScheduler; |
| 94 | 95 |
| 95 private LongSparseArray<RequestMetadata> mRequestMetadata; | 96 private LongSparseArray<RequestMetadata> mRequestMetadata; |
| 96 // TODO(romax): Use actual policy to determine the timeout. | 97 // TODO(romax): Use actual policy to determine the timeout. |
| 97 private Long mTimeoutPerUrlInSeconds = 0L; | 98 private Long mTimeoutPerUrlInSeconds = 0L; |
| 98 private OutputStreamWriter mLogOutput; | 99 private OutputStreamWriter mLogOutput; |
| 99 | 100 |
| 100 public OfflinePageSavePageLaterEvaluationTest() { | 101 public OfflinePageSavePageLaterEvaluationTest() { |
| 101 super(ChromeActivity.class); | 102 super(ChromeActivity.class); |
| 102 } | 103 } |
| 103 | 104 |
| 104 @Override | 105 @Override |
| 105 protected void setUp() throws Exception { | 106 protected void setUp() throws Exception { |
| 106 super.setUp(); | 107 super.setUp(); |
| 107 mRequestMetadata = new LongSparseArray<RequestMetadata>(); | 108 mRequestMetadata = new LongSparseArray<RequestMetadata>(); |
| 108 mCount = 0; | 109 mCount = 0; |
| 109 } | 110 } |
| 110 | 111 |
| 111 @Override | 112 @Override |
| 112 protected void tearDown() throws Exception { | 113 protected void tearDown() throws Exception { |
| 113 super.tearDown(); | |
| 114 NotificationManager notificationManager = | 114 NotificationManager notificationManager = |
| 115 (NotificationManager) ContextUtils.getApplicationContext().getSy stemService( | 115 (NotificationManager) ContextUtils.getApplicationContext().getSy stemService( |
| 116 Context.NOTIFICATION_SERVICE); | 116 Context.NOTIFICATION_SERVICE); |
| 117 notificationManager.cancelAll(); | 117 notificationManager.cancelAll(); |
| 118 final Semaphore mClearingSemaphore = new Semaphore(0); | |
|
Pete Williamson
2016/11/07 23:45:26
I see where we decrement the count and release the
romax
2016/11/08 00:18:35
This is used as a way to block the thread until ti
Pete Williamson
2016/11/08 00:51:35
Ah, so it is only called once, not once per reques
| |
| 119 ThreadUtils.runOnUiThread(new Runnable() { | |
| 120 @Override | |
| 121 public void run() { | |
| 122 mBridge.getRequestsInQueue(new Callback<SavePageRequest[]>() { | |
| 123 @Override | |
| 124 public void onResult(SavePageRequest[] results) { | |
| 125 ArrayList<Long> ids = new ArrayList<Long>(results.length ); | |
| 126 for (int i = 0; i < results.length; i++) { | |
| 127 ids.add(results[i].getRequestId()); | |
| 128 } | |
| 129 mBridge.removeRequestsFromQueue(ids, new Callback<Intege r>() { | |
| 130 @Override | |
| 131 public void onResult(Integer removedCount) { | |
| 132 mClearingSemaphore.release(); | |
| 133 } | |
| 134 }); | |
| 135 } | |
| 136 }); | |
| 137 } | |
| 138 }); | |
| 139 checkTrue(mClearingSemaphore.tryAcquire(REMOVE_REQUESTS_TIMEOUT_MS, Time Unit.MILLISECONDS), | |
| 140 "Timed out when clearing remaining requests!"); | |
| 141 super.tearDown(); | |
| 118 } | 142 } |
| 119 | 143 |
| 120 @Override | 144 @Override |
| 121 public void startMainActivity() throws InterruptedException { | 145 public void startMainActivity() throws InterruptedException { |
| 122 startMainActivityOnBlankPage(); | 146 startMainActivityOnBlankPage(); |
| 123 } | 147 } |
| 124 | 148 |
| 125 /** | 149 /** |
| 126 * Get a reader for a given input file path. | 150 * Get a reader for a given input file path. |
| 127 */ | 151 */ |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 * The test is the entry point for all kinds of testing of SavePageLater. | 466 * The test is the entry point for all kinds of testing of SavePageLater. |
| 443 * It is encouraged to use run_offline_page_evaluation_test.py to run this t est. | 467 * It is encouraged to use run_offline_page_evaluation_test.py to run this t est. |
| 444 */ | 468 */ |
| 445 @Manual | 469 @Manual |
| 446 public void testFailureRateWithTimeout() throws IOException, InterruptedExce ption { | 470 public void testFailureRateWithTimeout() throws IOException, InterruptedExce ption { |
| 447 parseConfigFile(); | 471 parseConfigFile(); |
| 448 setUpIOAndBridge(mUseTestScheduler); | 472 setUpIOAndBridge(mUseTestScheduler); |
| 449 processUrls(mUrls); | 473 processUrls(mUrls); |
| 450 } | 474 } |
| 451 } | 475 } |
| OLD | NEW |