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

Side by Side Diff: chrome/browser/extensions/extension_apitest.cc

Issue 3353015: Implement gallery install API (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: erik comments Created 10 years, 3 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/extensions/extensions_service.h" 9 #include "chrome/browser/extensions/extensions_service.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 default: 74 default:
75 NOTREACHED(); 75 NOTREACHED();
76 } 76 }
77 } 77 }
78 78
79 bool ExtensionApiTest::RunExtensionTest(const char* extension_name) { 79 bool ExtensionApiTest::RunExtensionTest(const char* extension_name) {
80 return RunExtensionTestImpl(extension_name, ""); 80 return RunExtensionTestImpl(extension_name, "");
81 } 81 }
82 82
83 bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name, 83 bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name,
84 const std::string& subtest_page) { 84 const std::string& page_url) {
85 DCHECK(!subtest_page.empty()) << "Argument subtest_page is required."; 85 DCHECK(!page_url.empty()) << "Argument page_url is required.";
86 return RunExtensionTestImpl(extension_name, subtest_page); 86 return RunExtensionTestImpl(extension_name, page_url);
87 } 87 }
88 88
89 // Load an extension and wait for it to notify of PASSED or FAILED. 89 bool ExtensionApiTest::RunPageTest(const std::string& page_url) {
90 return RunExtensionSubtest("", page_url);
91 }
92
93 // Load |extension_name| extension and/or |page_url| and wait for
94 // PASSED or FAILED notification.
90 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name, 95 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
91 const std::string& subtest_page) { 96 const std::string& page_url) {
92 ResultCatcher catcher; 97 ResultCatcher catcher;
93 LOG(INFO) << "Running ExtensionApiTest with: " << extension_name; 98 DCHECK(!std::string(extension_name).empty() || !page_url.empty()) <<
99 "extension_name and page_url cannot both be empty";
100 LOG(INFO) << "Running ExtensionApiTest";
94 101
95 if (!LoadExtension(test_data_dir_.AppendASCII(extension_name))) { 102 if (!std::string(extension_name).empty()) {
96 message_ = "Failed to load extension."; 103 LOG(INFO) << "Loading Extension: " << extension_name;
97 return false; 104 if (!LoadExtension(test_data_dir_.AppendASCII(extension_name))) {
105 message_ = "Failed to load extension.";
106 return false;
107 }
98 } 108 }
99 109
100 // If there is a subtest to load, navigate to the subtest page. 110 // If there is a page_url to load, navigate it.
101 if (!subtest_page.empty()) { 111 if (!page_url.empty()) {
102 ExtensionsService* service = browser()->profile()->GetExtensionsService(); 112 GURL url = GURL(page_url);
103 Extension* extension =
104 service->GetExtensionById(last_loaded_extension_id_, false);
105 if (!extension)
106 return false;
107 113
108 GURL url = extension->GetResourceURL(subtest_page); 114 // Note: We use is_valid() here in the expectation that the provided url
109 LOG(ERROR) << "Loading subtest page url: " << url.spec(); 115 // may lack a scheme & host and thus be a relative url within the loaded
116 // extension.
117 if (!url.is_valid()) {
118 DCHECK(!std::string(extension_name).empty()) <<
119 "Relative page_url given with no extension_name";
120
121 ExtensionsService* service = browser()->profile()->GetExtensionsService();
122 Extension* extension =
123 service->GetExtensionById(last_loaded_extension_id_, false);
124 if (!extension)
125 return false;
126
127 url = extension->GetResourceURL(page_url);
128 }
129
130 LOG(ERROR) << "Loading page url: " << url.spec();
110 ui_test_utils::NavigateToURL(browser(), url); 131 ui_test_utils::NavigateToURL(browser(), url);
111 } 132 }
112 133
113 if (!catcher.GetNextResult()) { 134 if (!catcher.GetNextResult()) {
114 message_ = catcher.message(); 135 message_ = catcher.message();
115 return false; 136 return false;
116 } else { 137 } else {
117 return true; 138 return true;
118 } 139 }
119 } 140 }
(...skipping 24 matching lines...) Expand all
144 message_ = "extension pointer is NULL."; 165 message_ = "extension pointer is NULL.";
145 return NULL; 166 return NULL;
146 } 167 }
147 return extension; 168 return extension;
148 } 169 }
149 170
150 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { 171 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) {
151 ExtensionBrowserTest::SetUpCommandLine(command_line); 172 ExtensionBrowserTest::SetUpCommandLine(command_line);
152 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); 173 test_data_dir_ = test_data_dir_.AppendASCII("api_test");
153 } 174 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_apitest.h ('k') | chrome/browser/extensions/extension_gallery_install_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698