OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_path.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/http/http_cache.h" | 9 #include "net/http/http_cache.h" |
10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
13 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 13 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
14 #include "webkit/tools/test_shell/test_shell.h" | 14 #include "webkit/tools/test_shell/test_shell.h" |
15 #include "webkit/tools/test_shell/test_shell_request_context.h" | 15 #include "webkit/tools/test_shell/test_shell_request_context.h" |
16 #include "webkit/tools/test_shell/test_shell_switches.h" | 16 #include "webkit/tools/test_shell/test_shell_switches.h" |
(...skipping 13 matching lines...) Expand all Loading... |
30 class NodeLeakTest : public TestShellTest { | 30 class NodeLeakTest : public TestShellTest { |
31 public: | 31 public: |
32 virtual void SetUp() { | 32 virtual void SetUp() { |
33 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 33 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
34 | 34 |
35 std::wstring js_flags = | 35 std::wstring js_flags = |
36 parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags); | 36 parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags); |
37 js_flags += L" --expose-gc"; | 37 js_flags += L" --expose-gc"; |
38 webkit_glue::SetJavaScriptFlags(js_flags); | 38 webkit_glue::SetJavaScriptFlags(js_flags); |
39 | 39 |
40 std::wstring cache_path = | 40 FilePath cache_path = FilePath::FromWStringHack( |
41 parsed_command_line.GetSwitchValue(test_shell::kCacheDir); | 41 parsed_command_line.GetSwitchValue(test_shell::kCacheDir)); |
42 if (cache_path.empty()) { | 42 if (cache_path.empty()) { |
43 PathService::Get(base::DIR_EXE, &cache_path); | 43 PathService::Get(base::DIR_EXE, &cache_path); |
44 file_util::AppendToPath(&cache_path, L"cache"); | 44 cache_path = cache_path.AppendASCII("cache"); |
45 } | 45 } |
46 | 46 |
47 if (parsed_command_line.HasSwitch(test_shell::kTestShellTimeOut)) { | 47 if (parsed_command_line.HasSwitch(test_shell::kTestShellTimeOut)) { |
48 const std::wstring timeout_str = parsed_command_line.GetSwitchValue( | 48 const std::wstring timeout_str = parsed_command_line.GetSwitchValue( |
49 test_shell::kTestShellTimeOut); | 49 test_shell::kTestShellTimeOut); |
50 int timeout_ms = | 50 int timeout_ms = |
51 static_cast<int>(StringToInt64(WideToUTF16Hack(timeout_str.c_str()))); | 51 static_cast<int>(StringToInt64(WideToUTF16Hack(timeout_str.c_str()))); |
52 if (timeout_ms > 0) | 52 if (timeout_ms > 0) |
53 TestShell::SetFileTestTimeout(timeout_ms); | 53 TestShell::SetFileTestTimeout(timeout_ms); |
54 } | 54 } |
55 | 55 |
56 // Optionally use playback mode (for instance if running automated tests). | 56 // Optionally use playback mode (for instance if running automated tests). |
57 net::HttpCache::Mode mode = | 57 net::HttpCache::Mode mode = |
58 parsed_command_line.HasSwitch(test_shell::kPlaybackMode) ? | 58 parsed_command_line.HasSwitch(test_shell::kPlaybackMode) ? |
59 net::HttpCache::PLAYBACK : net::HttpCache::NORMAL; | 59 net::HttpCache::PLAYBACK : net::HttpCache::NORMAL; |
60 SimpleResourceLoaderBridge::Init( | 60 SimpleResourceLoaderBridge::Init( |
61 new TestShellRequestContext(cache_path, mode, false)); | 61 new TestShellRequestContext(cache_path.ToWStringHack(), mode, false)); |
62 | 62 |
63 TestShellTest::SetUp(); | 63 TestShellTest::SetUp(); |
64 } | 64 } |
65 | 65 |
66 virtual void TearDown() { | 66 virtual void TearDown() { |
67 TestShellTest::TearDown(); | 67 TestShellTest::TearDown(); |
68 | 68 |
69 SimpleResourceLoaderBridge::Shutdown(); | 69 SimpleResourceLoaderBridge::Shutdown(); |
70 } | 70 } |
71 | 71 |
72 void NavigateToURL(const std::wstring& test_url) { | 72 void NavigateToURL(const std::wstring& test_url) { |
73 test_shell_->LoadURL(test_url.c_str()); | 73 test_shell_->LoadURL(test_url.c_str()); |
74 test_shell_->WaitTestFinished(); | 74 test_shell_->WaitTestFinished(); |
75 | 75 |
76 // Depends on TestShellTests::TearDown to load blank page and | 76 // Depends on TestShellTests::TearDown to load blank page and |
77 // the TestShell destructor to call garbage collection. | 77 // the TestShell destructor to call garbage collection. |
78 } | 78 } |
79 }; | 79 }; |
80 | 80 |
81 TEST_F(NodeLeakTest, TestURL) { | 81 TEST_F(NodeLeakTest, TestURL) { |
82 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 82 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
83 if (parsed_command_line.HasSwitch(kTestUrlSwitch)) { | 83 if (parsed_command_line.HasSwitch(kTestUrlSwitch)) { |
84 NavigateToURL(parsed_command_line.GetSwitchValue(kTestUrlSwitch).c_str()); | 84 NavigateToURL(parsed_command_line.GetSwitchValue(kTestUrlSwitch).c_str()); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
OLD | NEW |