| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.base.test.util; | 5 package org.chromium.base.test.util; |
| 6 | 6 |
| 7 import junit.framework.Assert; | 7 import junit.framework.Assert; |
| 8 | 8 |
| 9 import org.chromium.base.PathUtils; | 9 import org.chromium.base.PathUtils; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Collection of URL utilities. | 12 * Collection of URL utilities. |
| 13 */ | 13 */ |
| 14 public class UrlUtils { | 14 public class UrlUtils { |
| 15 private static final String DATA_DIR = "/chrome/test/data/"; | 15 private static final String DATA_DIR = "/chrome/test/data/"; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Construct the full path of a test data file. | 18 * Construct the full path of a test data file. |
| 19 * @param path Pathname relative to external/chrome/test/data | 19 * @param path Pathname relative to external/chrome/test/data |
| 20 */ | 20 */ |
| 21 public static String getTestFilePath(String path) { | 21 public static String getTestFilePath(String path) { |
| 22 // TODO(jbudorick): Remove DATA_DIR once everything has been isolated. c
rbug/400499 | 22 // TODO(jbudorick): Remove DATA_DIR once everything has been isolated. c
rbug/400499 |
| 23 return PathUtils.getExternalStorageDirectory() + DATA_DIR + path; | 23 return getIsolatedTestFilePath(DATA_DIR + path); |
| 24 } | 24 } |
| 25 | 25 |
| 26 // TODO(jbudorick): Remove this function once everything has been isolated a
nd switched back | 26 // TODO(jbudorick): Remove this function once everything has been isolated a
nd switched back |
| 27 // to getTestFilePath. crbug/400499 | 27 // to getTestFilePath. crbug/400499 |
| 28 /** | 28 /** |
| 29 * Construct the full path of a test data file. | 29 * Construct the full path of a test data file. |
| 30 * @param path Pathname relative to external/ | 30 * @param path Pathname relative to external/ |
| 31 */ | 31 */ |
| 32 public static String getIsolatedTestFilePath(String path) { | 32 public static String getIsolatedTestFilePath(String path) { |
| 33 return PathUtils.getExternalStorageDirectory() + "/" + path; | 33 return getIsolatedTestRoot() + "/" + path; |
| 34 } | 34 } |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Returns the root of the test data directory. |
| 38 */ |
| 39 public static String getIsolatedTestRoot() { |
| 40 return PathUtils.getExternalStorageDirectory() + "/chromium_tests_root"; |
| 41 } |
| 42 |
| 43 /** |
| 37 * Construct a suitable URL for loading a test data file. | 44 * Construct a suitable URL for loading a test data file. |
| 38 * @param path Pathname relative to external/chrome/test/data | 45 * @param path Pathname relative to external/chrome/test/data |
| 39 */ | 46 */ |
| 40 public static String getTestFileUrl(String path) { | 47 public static String getTestFileUrl(String path) { |
| 41 return "file://" + getTestFilePath(path); | 48 return "file://" + getTestFilePath(path); |
| 42 } | 49 } |
| 43 | 50 |
| 44 // TODO(jbudorick): Remove this function once everything has been isolated a
nd switched back | 51 // TODO(jbudorick): Remove this function once everything has been isolated a
nd switched back |
| 45 // to getTestFileUrl. crbug/400499 | 52 // to getTestFileUrl. crbug/400499 |
| 46 /** | 53 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 String encoded = | 71 String encoded = |
| 65 "data:text/html;utf-8," + java.net.URLEncoder.encode(html, "
UTF-8"); | 72 "data:text/html;utf-8," + java.net.URLEncoder.encode(html, "
UTF-8"); |
| 66 encoded = encoded.replace("+", "%20"); | 73 encoded = encoded.replace("+", "%20"); |
| 67 return encoded; | 74 return encoded; |
| 68 } catch (java.io.UnsupportedEncodingException e) { | 75 } catch (java.io.UnsupportedEncodingException e) { |
| 69 Assert.fail("Unsupported encoding: " + e.getMessage()); | 76 Assert.fail("Unsupported encoding: " + e.getMessage()); |
| 70 return null; | 77 return null; |
| 71 } | 78 } |
| 72 } | 79 } |
| 73 } | 80 } |
| OLD | NEW |