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
3 // found in the LICENSE file.
6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_commands.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/browser_test_utils.h"
19 #include "extensions/browser/extension_system.h"
20 #include "extensions/browser/process_manager.h"
22 using content::RenderViewHost
;
23 using content::WebContents
;
24 using extensions::Extension
;
26 class GtalkExtensionTest
: public ExtensionBrowserTest
{
28 extensions::ProcessManager
* GetProcessManager() {
29 return extensions::ExtensionSystem::Get(browser()->profile())->
33 void InstallGtalkExtension(const std::string
& version
) {
34 const Extension
* extension
= InstallExtensionWithUIAutoConfirm(
35 test_data_dir_
.AppendASCII("gtalk").AppendASCII(version
+ ".crx"),
37 installed_extension_id_
= extension
->id();
40 const std::string
& GetInstalledExtensionId() {
41 return installed_extension_id_
;
44 RenderViewHost
* GetViewer() {
45 std::vector
<RenderViewHost
*> views
= GetMatchingViews(GetViewerUrl());
46 EXPECT_EQ(1U, views
.size());
52 std::string
GetViewerUrl() {
53 return "chrome-extension://" + GetInstalledExtensionId() + "/viewer.html";
56 std::vector
<RenderViewHost
*> GetMatchingViews(std::string url_query
) {
57 extensions::ProcessManager
* manager
= GetProcessManager();
58 extensions::ProcessManager::ViewSet all_views
= manager
->GetAllViews();
59 std::vector
<RenderViewHost
*> matching_views
;
60 for (extensions::ProcessManager::ViewSet::const_iterator iter
=
61 all_views
.begin(); iter
!= all_views
.end(); ++iter
) {
62 WebContents
* web_contents
= WebContents::FromRenderViewHost(*iter
);
63 std::string url
= web_contents
->GetURL().spec();
64 if (url
.find(url_query
) != std::string::npos
)
65 matching_views
.push_back(*iter
);
67 return matching_views
;
70 std::string
ReadCurrentVersion() {
72 EXPECT_TRUE(base::ReadFileToString(
73 test_data_dir_
.AppendASCII("gtalk").AppendASCII("current_version"),
79 std::string installed_extension_id_
;
82 IN_PROC_BROWSER_TEST_F(GtalkExtensionTest
, InstallCurrent
) {
83 content::WindowedNotificationObserver
panel_loaded(
84 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED
,
85 content::NotificationService::AllSources());
86 InstallGtalkExtension(ReadCurrentVersion());
88 ASSERT_TRUE(GetViewer());