|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 3 | + * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +#include "brave/browser/extensions/brave_webstore_inline_installer.h" |
| 6 | +#include "chrome/browser/ui/browser.h" |
| 7 | +#include "chrome/test/base/in_process_browser_test.h" |
| 8 | +#include "chrome/test/base/ui_test_utils.h" |
| 9 | +#include "content/public/test/browser_test_utils.h" |
| 10 | + |
| 11 | +void OnInstalled(bool success, const std::string& error, |
| 12 | + extensions::webstore_install::Result result) { |
| 13 | +} |
| 14 | + |
| 15 | +class BraveWebstoreBrowserTest : public InProcessBrowserTest { |
| 16 | + public: |
| 17 | + void SetUpOnMainThread() override { |
| 18 | + InProcessBrowserTest::SetUpOnMainThread(); |
| 19 | + extension_id_ = "apdfllckaahabafndbhieahigkjlhalf"; |
| 20 | + } |
| 21 | + |
| 22 | + content::WebContents* contents() { |
| 23 | + return browser()->tab_strip_model()->GetActiveWebContents(); |
| 24 | + } |
| 25 | + |
| 26 | + bool NavigateToURLUntilLoadStop(const GURL& url) { |
| 27 | + ui_test_utils::NavigateToURL(browser(), url); |
| 28 | + return WaitForLoadStop(contents()); |
| 29 | + } |
| 30 | + |
| 31 | + int GetTabCount() const { |
| 32 | + return browser()->tab_strip_model()->count(); |
| 33 | + } |
| 34 | + |
| 35 | + bool CheckInlineInstallPermitted() { |
| 36 | + base::DictionaryValue webstore_data; |
| 37 | + std::string err; |
| 38 | + auto* installer = new extensions::BraveWebstoreInlineInstaller(contents(), |
| 39 | + contents()->GetMainFrame(), extension_id(), GURL(), |
| 40 | + base::Bind(&OnInstalled)); |
| 41 | + return installer->CheckInlineInstallPermitted(webstore_data, &err); |
| 42 | + } |
| 43 | + |
| 44 | + std::string extension_id() const { |
| 45 | + return extension_id_; |
| 46 | + } |
| 47 | + |
| 48 | + protected: |
| 49 | + std::string extension_id_; |
| 50 | +}; |
| 51 | + |
| 52 | +IN_PROC_BROWSER_TEST_F(BraveWebstoreBrowserTest, |
| 53 | + RedirectsUserToChromeWebStore) { |
| 54 | + // Inline install should not be permitted. |
| 55 | + ASSERT_FALSE(CheckInlineInstallPermitted()); |
| 56 | + // Inline install should create a second tab for the web-contents. |
| 57 | + GURL url(base::StringPrintf(extensions::kWebstoreUrlFormat, |
| 58 | + extension_id().c_str())); |
| 59 | + ASSERT_EQ(GetTabCount(), 2); |
| 60 | + ASSERT_STREQ(browser()->tab_strip_model()->GetWebContentsAt(1)->GetVisibleURL().spec().c_str(), url.spec().c_str()); |
| 61 | +} |
0 commit comments