Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(804)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java

Issue 2529603004: [Offline Pages] Expanding event logger to be used by harness. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
index 550ee623bf500777786a7f6bdce49f1b1846caec..a1e9e5090cf2a184a0962ae8b31e5186bc48614f 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java
@@ -97,7 +97,6 @@ public class OfflinePageSavePageLaterEvaluationTest
private LongSparseArray<RequestMetadata> mRequestMetadata;
// TODO(romax): Use actual policy to determine the timeout.
private Long mTimeoutPerUrlInSeconds = 0L;
- private OutputStreamWriter mLogOutput;
public OfflinePageSavePageLaterEvaluationTest() {
super(ChromeActivity.class);
@@ -139,6 +138,7 @@ public class OfflinePageSavePageLaterEvaluationTest
});
checkTrue(mClearingSemaphore.tryAcquire(REMOVE_REQUESTS_TIMEOUT_MS, TimeUnit.MILLISECONDS),
"Timed out when clearing remaining requests!");
+ mBridge.closeLog();
super.tearDown();
}
@@ -179,33 +179,26 @@ public class OfflinePageSavePageLaterEvaluationTest
for (String file : files) {
File currentFile = new File(externalArchiveDir.getPath(), file);
if (!currentFile.delete()) {
- logError(file + " cannot be deleted when clearing previous archives.");
+ logInOutput(
+ file + " cannot be deleted when clearing previous archives.");
}
}
}
}
if (!externalArchiveDir.mkdir()) {
- logError("Cannot create directory on external storage to store saved pages.");
+ logInOutput("Cannot create directory on external storage to store saved pages.");
}
} catch (SecurityException e) {
- logError("Failed to delete or create external archive folder!");
+ logInOutput("Failed to delete or create external archive folder!");
}
return externalArchiveDir;
}
/**
- * Logs error in both console and output file.
+ * Print log message in output file through evaluation bridge.
*/
- private void logError(String error) {
- Log.e(TAG, error);
- if (mLogOutput != null) {
- try {
- mLogOutput.write(error + NEW_LINE);
- mLogOutput.flush();
- } catch (Exception e) {
- Log.e(TAG, e.getMessage(), e);
- }
- }
+ private void logInOutput(String message) {
dougarnett 2016/11/28 23:02:44 name confusing to me - why not just "log()"?
romax 2016/11/30 00:15:09 Done.
+ mBridge.log(TAG, message);
}
/**
@@ -213,14 +206,7 @@ public class OfflinePageSavePageLaterEvaluationTest
*/
private void checkTrue(boolean condition, String message) {
if (!condition) {
- logError(message);
- if (mLogOutput != null) {
- try {
- mLogOutput.close();
- } catch (IOException e) {
- Log.e(TAG, e.getMessage(), e);
- }
- }
+ logInOutput(message);
fail();
}
}
@@ -239,7 +225,7 @@ public class OfflinePageSavePageLaterEvaluationTest
Profile profile = Profile.getLastUsedProfile();
mBridge = OfflinePageEvaluationBridge.getForProfile(profile, useTestingScheduler);
if (mBridge == null) {
- logError("OfflinePageEvaluationBridge initialization failed!");
+ fail("OfflinePageEvaluationBridge initialization failed!");
return;
}
if (mBridge.isOfflinePageModelLoaded()) {
@@ -266,12 +252,6 @@ public class OfflinePageSavePageLaterEvaluationTest
*/
protected void setUpIOAndBridge(final boolean useCustomScheduler) throws InterruptedException {
try {
- mLogOutput = getOutputStream(LOG_OUTPUT_FILE_PATH);
- } catch (IOException e) {
- Log.wtf(TAG, "Cannot set output file!");
- Log.wtf(TAG, e.getMessage(), e);
- }
- try {
getUrlListFromInputFile(INPUT_FILE_PATH);
} catch (IOException e) {
Log.wtf(TAG, "Cannot read input file!");
@@ -307,6 +287,14 @@ public class OfflinePageSavePageLaterEvaluationTest
public void savePageRequestChanged(SavePageRequest request) {}
};
mBridge.addObserver(mObserver);
+ try {
+ File logOutputFile =
+ new File(Environment.getExternalStorageDirectory(), LOG_OUTPUT_FILE_PATH);
+ mBridge.setLogOutputFile(logOutputFile);
+ } catch (IOException e) {
+ Log.wtf(TAG, "Cannot set log output file!");
dougarnett 2016/11/28 23:02:44 consider just adding e arg here and not doing 2nd
romax 2016/11/30 00:15:10 Done.
dougarnett 2016/11/30 18:05:25 Don't see a related change uploaded for this
romax 2016/12/01 01:47:52 Done. Sorry I lost the change.
+ Log.wtf(TAG, e.getMessage(), e);
+ }
}
/**
@@ -326,7 +314,7 @@ public class OfflinePageSavePageLaterEvaluationTest
private void processUrls(List<String> urls) throws InterruptedException, IOException {
if (mBridge == null) {
- logError("Test initialization error, aborting. No results would be written.");
+ fail("Test initialization error, aborting. No results would be written.");
return;
}
mDoneSemaphore = new Semaphore(0);
@@ -429,10 +417,11 @@ public class OfflinePageSavePageLaterEvaluationTest
private void writeResults(boolean completed) throws IOException, InterruptedException {
loadSavedPages();
OutputStreamWriter output = getOutputStream(RESULT_OUTPUT_FILE_PATH);
+ logInOutput("ROMAX start writing results.");
try {
int failedCount = 0;
if (!completed) {
- logError("Test terminated before all requests completed.");
+ logInOutput("Test terminated before all requests completed.");
}
File externalArchiveDir = getExternalArchiveDir();
for (int i = 0; i < mRequestMetadata.size(); i++) {
@@ -455,7 +444,7 @@ public class OfflinePageSavePageLaterEvaluationTest
File originalPage = new File(page.getFilePath());
File externalPage = new File(externalArchiveDir, originalPage.getName());
if (!OfflinePageUtils.copyToShareableLocation(originalPage, externalPage)) {
- logError("Saved page for url " + page.getUrl() + " cannot be moved.");
+ logInOutput("Saved page for url " + page.getUrl() + " cannot be moved.");
}
}
output.write(String.format(
@@ -468,9 +457,6 @@ public class OfflinePageSavePageLaterEvaluationTest
if (output != null) {
output.close();
}
- if (mLogOutput != null) {
- mLogOutput.close();
- }
}
}

Powered by Google App Engine
This is Rietveld 408576698