OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; | 32 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; |
33 virtual void SetUpOnMainThread() OVERRIDE; | 33 virtual void SetUpOnMainThread() OVERRIDE; |
34 | 34 |
35 // Run the attach function. If |expected_error| is not empty, then the | 35 // Run the attach function. If |expected_error| is not empty, then the |
36 // function should fail with the error. Otherwise, the function is expected | 36 // function should fail with the error. Otherwise, the function is expected |
37 // to succeed. | 37 // to succeed. |
38 testing::AssertionResult RunAttachFunction(const GURL& url, | 38 testing::AssertionResult RunAttachFunction(const GURL& url, |
39 const std::string& expected_error); | 39 const std::string& expected_error); |
40 | 40 |
41 const Extension* extension() const { return extension_; } | 41 const Extension* extension() const { return extension_.get(); } |
42 base::CommandLine* command_line() const { return command_line_; } | 42 base::CommandLine* command_line() const { return command_line_; } |
43 | 43 |
44 private: | 44 private: |
45 // The command-line for the test process, preserved in order to modify | 45 // The command-line for the test process, preserved in order to modify |
46 // mid-test. | 46 // mid-test. |
47 base::CommandLine* command_line_; | 47 base::CommandLine* command_line_; |
48 | 48 |
49 // A basic extension with the debugger permission. | 49 // A basic extension with the debugger permission. |
50 scoped_refptr<const Extension> extension_; | 50 scoped_refptr<const Extension> extension_; |
51 }; | 51 }; |
(...skipping 16 matching lines...) Expand all Loading... |
68 } | 68 } |
69 | 69 |
70 testing::AssertionResult DebuggerApiTest::RunAttachFunction( | 70 testing::AssertionResult DebuggerApiTest::RunAttachFunction( |
71 const GURL& url, const std::string& expected_error) { | 71 const GURL& url, const std::string& expected_error) { |
72 ui_test_utils::NavigateToURL(browser(), url); | 72 ui_test_utils::NavigateToURL(browser(), url); |
73 content::WebContents* web_contents = | 73 content::WebContents* web_contents = |
74 browser()->tab_strip_model()->GetActiveWebContents(); | 74 browser()->tab_strip_model()->GetActiveWebContents(); |
75 int tab_id = SessionTabHelper::IdForTab(web_contents); | 75 int tab_id = SessionTabHelper::IdForTab(web_contents); |
76 scoped_refptr<DebuggerAttachFunction> attach_function = | 76 scoped_refptr<DebuggerAttachFunction> attach_function = |
77 new DebuggerAttachFunction(); | 77 new DebuggerAttachFunction(); |
78 attach_function->set_extension(extension_); | 78 attach_function->set_extension(extension_.get()); |
79 std::string args = base::StringPrintf("[{\"tabId\": %d}, \"1.1\"]", tab_id); | 79 std::string args = base::StringPrintf("[{\"tabId\": %d}, \"1.1\"]", tab_id); |
80 | 80 |
81 if (!expected_error.empty()) { | 81 if (!expected_error.empty()) { |
82 std::string actual_error = | 82 std::string actual_error = |
83 extension_function_test_utils::RunFunctionAndReturnError( | 83 extension_function_test_utils::RunFunctionAndReturnError( |
84 attach_function, args, browser()); | 84 attach_function.get(), args, browser()); |
85 if (actual_error != expected_error) { | 85 if (actual_error != expected_error) { |
86 return testing::AssertionFailure() << "Did not get correct error: " | 86 return testing::AssertionFailure() << "Did not get correct error: " |
87 << "expected: " << expected_error << ", found: " << actual_error; | 87 << "expected: " << expected_error << ", found: " << actual_error; |
88 } | 88 } |
89 } else { | 89 } else { |
90 if (!RunFunction(attach_function, | 90 if (!RunFunction(attach_function.get(), |
91 args, | 91 args, |
92 browser(), | 92 browser(), |
93 extension_function_test_utils::NONE)) { | 93 extension_function_test_utils::NONE)) { |
94 return testing::AssertionFailure() << "Could not run function: " | 94 return testing::AssertionFailure() << "Could not run function: " |
95 << attach_function->GetError(); | 95 << attach_function->GetError(); |
96 } | 96 } |
97 | 97 |
98 // Clean up and detach. | 98 // Clean up and detach. |
99 scoped_refptr<DebuggerDetachFunction> detach_function = | 99 scoped_refptr<DebuggerDetachFunction> detach_function = |
100 new DebuggerDetachFunction(); | 100 new DebuggerDetachFunction(); |
101 detach_function->set_extension(extension_); | 101 detach_function->set_extension(extension_.get()); |
102 if (!RunFunction(detach_function, | 102 if (!RunFunction(detach_function.get(), |
103 base::StringPrintf("[{\"tabId\": %d}]", tab_id), | 103 base::StringPrintf("[{\"tabId\": %d}]", tab_id), |
104 browser(), | 104 browser(), |
105 extension_function_test_utils::NONE)) { | 105 extension_function_test_utils::NONE)) { |
106 return testing::AssertionFailure() << "Could not detach: " | 106 return testing::AssertionFailure() << "Could not detach: " |
107 << detach_function->GetError(); | 107 << detach_function->GetError(); |
108 } | 108 } |
109 } | 109 } |
110 return testing::AssertionSuccess(); | 110 return testing::AssertionSuccess(); |
111 } | 111 } |
112 | 112 |
(...skipping 24 matching lines...) Expand all Loading... |
137 extension()->id().c_str())), | 137 extension()->id().c_str())), |
138 std::string())); | 138 std::string())); |
139 | 139 |
140 // Append extensions on chrome urls switch. The extension should now be able | 140 // Append extensions on chrome urls switch. The extension should now be able |
141 // to debug any extension. | 141 // to debug any extension. |
142 command_line()->AppendSwitch(switches::kExtensionsOnChromeURLs); | 142 command_line()->AppendSwitch(switches::kExtensionsOnChromeURLs); |
143 EXPECT_TRUE(RunAttachFunction(other_ext_url, std::string())); | 143 EXPECT_TRUE(RunAttachFunction(other_ext_url, std::string())); |
144 } | 144 } |
145 | 145 |
146 } // namespace extensions | 146 } // namespace extensions |
OLD | NEW |