diff options
Diffstat (limited to 'chromium/chrome/browser/ui/webui/test_data_source.cc')
-rw-r--r-- | chromium/chrome/browser/ui/webui/test_data_source.cc | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/chromium/chrome/browser/ui/webui/test_data_source.cc b/chromium/chrome/browser/ui/webui/test_data_source.cc index 3c2b5ac0d41..1fbe67324c0 100644 --- a/chromium/chrome/browser/ui/webui/test_data_source.cc +++ b/chromium/chrome/browser/ui/webui/test_data_source.cc @@ -25,6 +25,19 @@ namespace { const char kModuleQuery[] = "module="; } // namespace +TestDataSource::TestDataSource(std::string root) { + base::FilePath test_data; + CHECK(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data)); + src_root_ = test_data.AppendASCII(root).NormalizePathSeparators(); + DCHECK(test_data.IsParent(src_root_)); + + base::FilePath exe_dir; + base::PathService::Get(base::DIR_EXE, &exe_dir); + gen_root_ = exe_dir.AppendASCII("gen/chrome/test/data/" + root) + .NormalizePathSeparators(); + DCHECK(exe_dir.IsParent(gen_root_)); +} + std::string TestDataSource::GetSource() { return "test"; } @@ -33,6 +46,15 @@ void TestDataSource::StartDataRequest( const std::string& path, const content::WebContents::Getter& wc_getter, const content::URLDataSource::GotDataCallback& callback) { + if (path == "strings.m.js") { + std::string output = "import {loadTimeData} from "; + output.append("'chrome://resources/js/load_time_data.m.js';\n"); + output.append("loadTimeData.data = {};"); + scoped_refptr<base::RefCountedString> response = + base::RefCountedString::TakeString(&output); + callback.Run(response.get()); + return; + } base::PostTask( FROM_HERE, {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_BLOCKING}, @@ -48,7 +70,9 @@ std::string TestDataSource::GetMimeType(const std::string& path) { return "text/html"; } // The test data source currently only serves HTML and JS. - CHECK(base::EndsWith(path, ".js", base::CompareCase::INSENSITIVE_ASCII)); + CHECK(base::EndsWith(path, ".js", base::CompareCase::INSENSITIVE_ASCII)) + << "Tried to read file with unexpected type from test data source: " + << path; return "application/javascript"; } @@ -72,22 +96,6 @@ GURL TestDataSource::GetURLForPath(const std::string& path) { void TestDataSource::ReadFile( const std::string& path, const content::URLDataSource::GotDataCallback& callback) { - if (src_root_.empty()) { - base::FilePath test_data; - CHECK(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data)); - src_root_ = test_data.Append(FILE_PATH_LITERAL("webui")); - } - - if (gen_root_.empty()) { - std::string gen_path = "gen/chrome/test/data/webui/"; -#if defined(OS_WIN) - base::ReplaceChars(gen_path, "//", "\\", &gen_path); -#endif - base::FilePath exe_dir; - base::PathService::Get(base::DIR_EXE, &exe_dir); - gen_root_ = exe_dir.AppendASCII(gen_path); - } - std::string content; GURL url = GetURLForPath(path); |