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

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

Issue 62713003: Move ExtensionProcessManager to src/extensions, part 4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/bind.h" 5 #include "base/bind.h"
6 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_browsertest.h" 8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/extensions/extension_host.h" 9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_process_manager.h"
11 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h" 14 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
20 #include "extensions/browser/process_manager.h"
21 21
22 using content::RenderViewHost; 22 using content::RenderViewHost;
23 using content::WebContents; 23 using content::WebContents;
24 using extensions::Extension; 24 using extensions::Extension;
25 25
26 class GtalkExtensionTest : public ExtensionBrowserTest { 26 class GtalkExtensionTest : public ExtensionBrowserTest {
27 protected: 27 protected:
28 ExtensionProcessManager* GetExtensionProcessManager() { 28 extensions::ProcessManager* GetProcessManager() {
29 return extensions::ExtensionSystem::Get(browser()->profile())-> 29 return extensions::ExtensionSystem::Get(browser()->profile())->
30 process_manager(); 30 process_manager();
31 } 31 }
32 32
33 void InstallGtalkExtension(const std::string& version) { 33 void InstallGtalkExtension(const std::string& version) {
34 const Extension* extension = InstallExtensionWithUIAutoConfirm( 34 const Extension* extension = InstallExtensionWithUIAutoConfirm(
35 test_data_dir_.AppendASCII("gtalk").AppendASCII(version + ".crx"), 35 test_data_dir_.AppendASCII("gtalk").AppendASCII(version + ".crx"),
36 1, browser()); 36 1, browser());
37 installed_extension_id_ = extension->id(); 37 installed_extension_id_ = extension->id();
38 } 38 }
39 39
40 const std::string& GetInstalledExtensionId() { 40 const std::string& GetInstalledExtensionId() {
41 return installed_extension_id_; 41 return installed_extension_id_;
42 } 42 }
43 43
44 RenderViewHost* GetViewer() { 44 RenderViewHost* GetViewer() {
45 std::vector<RenderViewHost*> views = GetMatchingViews(GetViewerUrl()); 45 std::vector<RenderViewHost*> views = GetMatchingViews(GetViewerUrl());
46 EXPECT_EQ(1U, views.size()); 46 EXPECT_EQ(1U, views.size());
47 if (views.empty()) 47 if (views.empty())
48 return NULL; 48 return NULL;
49 return views.front(); 49 return views.front();
50 } 50 }
51 51
52 std::string GetViewerUrl() { 52 std::string GetViewerUrl() {
53 return "chrome-extension://" + GetInstalledExtensionId() + "/viewer.html"; 53 return "chrome-extension://" + GetInstalledExtensionId() + "/viewer.html";
54 } 54 }
55 55
56 std::vector<RenderViewHost*> GetMatchingViews(std::string url_query) { 56 std::vector<RenderViewHost*> GetMatchingViews(std::string url_query) {
57 ExtensionProcessManager* manager = GetExtensionProcessManager(); 57 extensions::ProcessManager* manager = GetProcessManager();
58 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); 58 extensions::ProcessManager::ViewSet all_views = manager->GetAllViews();
59 std::vector<RenderViewHost*> matching_views; 59 std::vector<RenderViewHost*> matching_views;
60 for (ExtensionProcessManager::ViewSet::const_iterator iter = 60 for (extensions::ProcessManager::ViewSet::const_iterator iter =
61 all_views.begin(); iter != all_views.end(); ++iter) { 61 all_views.begin(); iter != all_views.end(); ++iter) {
62 WebContents* web_contents = WebContents::FromRenderViewHost(*iter); 62 WebContents* web_contents = WebContents::FromRenderViewHost(*iter);
63 std::string url = web_contents->GetURL().spec(); 63 std::string url = web_contents->GetURL().spec();
64 if (url.find(url_query) != std::string::npos) 64 if (url.find(url_query) != std::string::npos)
65 matching_views.push_back(*iter); 65 matching_views.push_back(*iter);
66 } 66 }
67 return matching_views; 67 return matching_views;
68 } 68 }
69 69
70 std::string ReadCurrentVersion() { 70 std::string ReadCurrentVersion() {
71 std::string response; 71 std::string response;
72 EXPECT_TRUE(base::ReadFileToString( 72 EXPECT_TRUE(base::ReadFileToString(
73 test_data_dir_.AppendASCII("gtalk").AppendASCII("current_version"), 73 test_data_dir_.AppendASCII("gtalk").AppendASCII("current_version"),
74 &response)); 74 &response));
75 return response; 75 return response;
76 } 76 }
77 77
78 private: 78 private:
79 std::string installed_extension_id_; 79 std::string installed_extension_id_;
80 }; 80 };
81 81
82 IN_PROC_BROWSER_TEST_F(GtalkExtensionTest, InstallCurrent) { 82 IN_PROC_BROWSER_TEST_F(GtalkExtensionTest, InstallCurrent) {
83 content::WindowedNotificationObserver panel_loaded( 83 content::WindowedNotificationObserver panel_loaded(
84 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, 84 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED,
85 content::NotificationService::AllSources()); 85 content::NotificationService::AllSources());
86 InstallGtalkExtension(ReadCurrentVersion()); 86 InstallGtalkExtension(ReadCurrentVersion());
87 panel_loaded.Wait(); 87 panel_loaded.Wait();
88 ASSERT_TRUE(GetViewer()); 88 ASSERT_TRUE(GetViewer());
89 } 89 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/gpu_browsertest.cc ('k') | chrome/browser/extensions/lazy_background_page_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698