Skip to content

Commit

Permalink
[IntentHandling] Add browser tests for intent picker.
Browse files Browse the repository at this point in the history
This CL adds browser tests for intent picker on Chrome OS.

BUG=853604

Change-Id: If1543890d9e2b60de2a2fcb5e71f6baf4fcd85d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2308621
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801642}
  • Loading branch information
Maggie Cai authored and Commit Bot committed Aug 26, 2020
1 parent 64a8dce commit 688bbc0
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/ui/views/intent_picker_bubble_view.h
Expand Up @@ -113,6 +113,8 @@ class IntentPickerBubbleView : public LocationBarBubbleDelegateView,
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, WebContentsTiedToBubble);
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, WindowTitle);
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, ButtonLabels);
FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewBrowserTestChromeOS,
BubblePopOut);

static std::unique_ptr<IntentPickerBubbleView> CreateBubbleViewForTesting(
views::View* anchor_view,
Expand Down
@@ -0,0 +1,98 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/intent_picker_bubble_view.h"

#include "base/test/scoped_feature_list.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/app_service_test.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/location_bar/intent_picker_view.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/services/app_service/public/cpp/intent_filter_util.h"
#include "components/services/app_service/public/cpp/intent_test_util.h"
#include "components/services/app_service/public/cpp/intent_util.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "content/public/test/browser_test.h"
#include "url/gurl.h"
#include "url/url_constants.h"

namespace {
const char kAppId1[] = "abcdefg";
} // namespace

class IntentPickerBubbleViewBrowserTestChromeOS : public InProcessBrowserTest {
public:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
app_service_test_.SetUp(browser()->profile());
app_service_proxy_ =
apps::AppServiceProxyFactory::GetForProfile(browser()->profile());
ASSERT_TRUE(app_service_proxy_);
}

void AddFakeAppWithIntentFilter(const std::string& app_id,
const std::string& app_name,
const GURL& url,
const apps::mojom::AppType app_type) {
std::vector<apps::mojom::AppPtr> apps;
auto app = apps::mojom::App::New();
app->app_id = app_id;
app->app_type = app_type;
app->name = app_name;
auto intent_filter = apps_util::CreateIntentFilterForUrlScope(url);
app->intent_filters.push_back(std::move(intent_filter));
apps.push_back(std::move(app));
app_service_proxy_->AppRegistryCache().OnApps(std::move(apps));
app_service_test_.WaitForAppService();
}

PageActionIconView* GetIntentPickerIcon() {
return BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider()
->GetPageActionIconView(PageActionIconType::kIntentPicker);
}

apps::AppServiceTest& app_service_test() { return app_service_test_; }

private:
apps::AppServiceProxy* app_service_proxy_ = nullptr;
apps::AppServiceTest app_service_test_;
};

IN_PROC_BROWSER_TEST_F(IntentPickerBubbleViewBrowserTestChromeOS,
BubblePopOut) {
GURL test_url("https://www.google.com/");
std::string app_name = "test_name";
AddFakeAppWithIntentFilter(kAppId1, app_name, test_url,
apps::mojom::AppType::kArc);
PageActionIconView* intent_picker_view = GetIntentPickerIcon();

chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));

// Navigate from a link.
NavigateParams params(browser(), test_url,
ui::PageTransition::PAGE_TRANSITION_LINK);

// Navigates and waits for loading to finish.
ui_test_utils::NavigateToURL(&params);
app_service_test().WaitForAppService();
EXPECT_TRUE(intent_picker_view->GetVisible());
EXPECT_TRUE(IntentPickerBubbleView::intent_picker_bubble_);
EXPECT_EQ(1U,
IntentPickerBubbleView::intent_picker_bubble_->GetScrollViewSize());
auto& app_info =
IntentPickerBubbleView::intent_picker_bubble_->app_info_for_testing();
ASSERT_EQ(1U, app_info.size());
EXPECT_EQ(kAppId1, app_info[0].launch_name);
EXPECT_EQ(app_name, app_info[0].display_name);
}
1 change: 1 addition & 0 deletions chrome/test/BUILD.gn
Expand Up @@ -2608,6 +2608,7 @@ if (!is_android) {
"../browser/ui/views/frame/immersive_mode_controller_ash_browsertest.cc",
"../browser/ui/views/frame/system_menu_model_builder_browsertest_chromeos.cc",
"../browser/ui/views/frame/top_controls_slide_controller_chromeos_browsertest.cc",
"../browser/ui/views/intent_picker_bubble_view_browsertest_chromeos.cc",
"../browser/ui/views/plugin_vm/plugin_vm_installer_view_browsertest.cc",
"../browser/ui/views/supervised_user/extension_install_blocked_by_parent_dialog_view_browsertest.cc",
"../browser/ui/views/supervised_user/parent_permission_dialog_view_browsertest.cc",
Expand Down

0 comments on commit 688bbc0

Please sign in to comment.