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 "chrome/browser/extensions/extension_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // This makes sure that we create the Default profile first, with no | 67 // This makes sure that we create the Default profile first, with no |
68 // ExtensionService and then the real profile with one, as we do when | 68 // ExtensionService and then the real profile with one, as we do when |
69 // running on chromeos. | 69 // running on chromeos. |
70 command_line->AppendSwitchASCII(switches::kLoginUser, | 70 command_line->AppendSwitchASCII(switches::kLoginUser, |
71 "TestUser@gmail.com"); | 71 "TestUser@gmail.com"); |
72 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 72 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
73 command_line->AppendSwitch(switches::kNoFirstRun); | 73 command_line->AppendSwitch(switches::kNoFirstRun); |
74 #endif | 74 #endif |
75 } | 75 } |
76 | 76 |
77 const Extension* ExtensionBrowserTest::LoadExtensionWithOptions( | 77 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( |
78 const FilePath& path, bool incognito_enabled, bool fileaccess_enabled) { | 78 const FilePath& path, int flags) { |
79 ExtensionService* service = browser()->profile()->GetExtensionService(); | 79 ExtensionService* service = browser()->profile()->GetExtensionService(); |
80 { | 80 { |
81 content::NotificationRegistrar registrar; | 81 content::NotificationRegistrar registrar; |
82 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 82 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
83 content::NotificationService::AllSources()); | 83 content::NotificationService::AllSources()); |
84 scoped_refptr<extensions::UnpackedInstaller> installer( | 84 scoped_refptr<extensions::UnpackedInstaller> installer( |
85 extensions::UnpackedInstaller::Create(service)); | 85 extensions::UnpackedInstaller::Create(service)); |
86 installer->set_prompt_for_plugins(false); | 86 installer->set_prompt_for_plugins(false); |
87 installer->Load(path); | 87 installer->Load(path); |
88 content::RunMessageLoop(); | 88 content::RunMessageLoop(); |
89 } | 89 } |
90 | 90 |
91 // Find the loaded extension by its path. See crbug.com/59531 for why | 91 // Find the loaded extension by its path. See crbug.com/59531 for why |
92 // we cannot just use last_loaded_extension_id_. | 92 // we cannot just use last_loaded_extension_id_. |
93 FilePath extension_path = path; | 93 FilePath extension_path = path; |
94 file_util::AbsolutePath(&extension_path); | 94 file_util::AbsolutePath(&extension_path); |
95 const Extension* extension = NULL; | 95 const Extension* extension = NULL; |
96 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 96 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
97 iter != service->extensions()->end(); ++iter) { | 97 iter != service->extensions()->end(); ++iter) { |
98 if ((*iter)->path() == extension_path) { | 98 if ((*iter)->path() == extension_path) { |
99 extension = *iter; | 99 extension = *iter; |
100 break; | 100 break; |
101 } | 101 } |
102 } | 102 } |
103 if (!extension) | 103 if (!extension) |
104 return NULL; | 104 return NULL; |
105 | 105 |
| 106 if (!(flags & kFlagIgnoreManifestWarnings)) { |
| 107 const Extension::InstallWarningVector& install_warnings = |
| 108 extension->install_warnings(); |
| 109 if (!install_warnings.empty()) { |
| 110 std::string install_warnings_message = StringPrintf( |
| 111 "Unexpected warnings when loading test extension %s:\n", |
| 112 path.AsUTF8Unsafe().c_str()); |
| 113 |
| 114 for (Extension::InstallWarningVector::const_iterator it = |
| 115 install_warnings.begin(); it != install_warnings.end(); ++it) { |
| 116 install_warnings_message += " " + it->message + "\n"; |
| 117 } |
| 118 |
| 119 EXPECT_TRUE(extension->install_warnings().empty()) << |
| 120 install_warnings_message; |
| 121 return NULL; |
| 122 } |
| 123 } |
| 124 |
106 const std::string extension_id = extension->id(); | 125 const std::string extension_id = extension->id(); |
107 | 126 |
108 // The call to OnExtensionInstalled ensures the other extension prefs | 127 // The call to OnExtensionInstalled ensures the other extension prefs |
109 // are set up with the defaults. | 128 // are set up with the defaults. |
110 service->extension_prefs()->OnExtensionInstalled( | 129 service->extension_prefs()->OnExtensionInstalled( |
111 extension, Extension::ENABLED, false, | 130 extension, Extension::ENABLED, false, |
112 StringOrdinal::CreateInitialOrdinal()); | 131 StringOrdinal::CreateInitialOrdinal()); |
113 | 132 |
114 // Toggling incognito or file access will reload the extension, so wait for | 133 // Toggling incognito or file access will reload the extension, so wait for |
115 // the reload and grab the new extension instance. The default state is | 134 // the reload and grab the new extension instance. The default state is |
116 // incognito disabled and file access enabled, so we don't wait in those | 135 // incognito disabled and file access enabled, so we don't wait in those |
117 // cases. | 136 // cases. |
118 { | 137 { |
119 content::WindowedNotificationObserver load_signal( | 138 content::WindowedNotificationObserver load_signal( |
120 chrome::NOTIFICATION_EXTENSION_LOADED, | 139 chrome::NOTIFICATION_EXTENSION_LOADED, |
121 content::Source<Profile>(browser()->profile())); | 140 content::Source<Profile>(browser()->profile())); |
122 CHECK(!service->IsIncognitoEnabled(extension_id)); | 141 CHECK(!service->IsIncognitoEnabled(extension_id)); |
123 | 142 |
124 if (incognito_enabled) { | 143 if (flags & kFlagEnableIncognito) { |
125 service->SetIsIncognitoEnabled(extension_id, incognito_enabled); | 144 service->SetIsIncognitoEnabled(extension_id, true); |
126 load_signal.Wait(); | 145 load_signal.Wait(); |
127 extension = service->GetExtensionById(extension_id, false); | 146 extension = service->GetExtensionById(extension_id, false); |
128 CHECK(extension) << extension_id << " not found after reloading."; | 147 CHECK(extension) << extension_id << " not found after reloading."; |
129 } | 148 } |
130 } | 149 } |
131 | 150 |
132 { | 151 { |
133 content::WindowedNotificationObserver load_signal( | 152 content::WindowedNotificationObserver load_signal( |
134 chrome::NOTIFICATION_EXTENSION_LOADED, | 153 chrome::NOTIFICATION_EXTENSION_LOADED, |
135 content::Source<Profile>(browser()->profile())); | 154 content::Source<Profile>(browser()->profile())); |
136 CHECK(service->AllowFileAccess(extension)); | 155 CHECK(service->AllowFileAccess(extension)); |
137 if (!fileaccess_enabled) { | 156 if (!(flags & kFlagEnableFileAccess)) { |
138 service->SetAllowFileAccess(extension, fileaccess_enabled); | 157 service->SetAllowFileAccess(extension, false); |
139 load_signal.Wait(); | 158 load_signal.Wait(); |
140 extension = service->GetExtensionById(extension_id, false); | 159 extension = service->GetExtensionById(extension_id, false); |
141 CHECK(extension) << extension_id << " not found after reloading."; | 160 CHECK(extension) << extension_id << " not found after reloading."; |
142 } | 161 } |
143 } | 162 } |
144 | 163 |
145 if (!WaitForExtensionViewsToLoad()) | 164 if (!WaitForExtensionViewsToLoad()) |
146 return NULL; | 165 return NULL; |
147 | 166 |
148 return extension; | 167 return extension; |
149 } | 168 } |
150 | 169 |
151 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { | 170 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { |
152 return LoadExtensionWithOptions(path, false, true); | 171 return LoadExtensionWithFlags(path, kFlagEnableFileAccess); |
153 } | 172 } |
154 | 173 |
155 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( | 174 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( |
156 const FilePath& path) { | 175 const FilePath& path) { |
157 return LoadExtensionWithOptions(path, true, true); | 176 return LoadExtensionWithFlags(path, |
| 177 kFlagEnableFileAccess | kFlagEnableIncognito); |
158 } | 178 } |
159 | 179 |
160 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( | 180 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( |
161 const FilePath& path) { | 181 const FilePath& path) { |
162 ExtensionService* service = browser()->profile()->GetExtensionService(); | 182 ExtensionService* service = browser()->profile()->GetExtensionService(); |
163 | 183 |
164 std::string manifest; | 184 std::string manifest; |
165 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename), | 185 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename), |
166 &manifest)) | 186 &manifest)) |
167 return NULL; | 187 return NULL; |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 case content::NOTIFICATION_LOAD_STOP: | 675 case content::NOTIFICATION_LOAD_STOP: |
656 VLOG(1) << "Got LOAD_STOP notification."; | 676 VLOG(1) << "Got LOAD_STOP notification."; |
657 MessageLoopForUI::current()->Quit(); | 677 MessageLoopForUI::current()->Quit(); |
658 break; | 678 break; |
659 | 679 |
660 default: | 680 default: |
661 NOTREACHED(); | 681 NOTREACHED(); |
662 break; | 682 break; |
663 } | 683 } |
664 } | 684 } |
OLD | NEW |