1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/test_browser_window.h"
#include <utility>
#include "base/feature_list.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/user_education/browser_user_education_interface.h"
#include "components/sharing_message/sharing_dialog_data.h"
#include "components/user_education/common/feature_promo/feature_promo_controller.h"
#include "components/user_education/common/feature_promo/feature_promo_handle.h"
#include "components/user_education/common/feature_promo/feature_promo_result.h"
#include "components/user_education/common/new_badge/new_badge_controller.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/mojom/window_show_state.mojom.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/color_provider_manager.h"
#include "ui/gfx/geometry/rect.h"
// Helpers --------------------------------------------------------------------
std::unique_ptr<Browser> CreateBrowserWithTestWindowForParams(
Browser::CreateParams params) {
DCHECK(!params.window);
auto window = std::make_unique<TestBrowserWindow>();
auto* window_ptr = window.get();
new TestBrowserWindowOwner(std::move(window));
params.window = window_ptr;
window_ptr->set_is_minimized(params.initial_show_state ==
ui::mojom::WindowShowState::kMinimized);
// Tests generally expect TestBrowserWindows not to be active.
window_ptr->set_is_active(
params.initial_show_state != ui::mojom::WindowShowState::kInactive &&
params.initial_show_state != ui::mojom::WindowShowState::kDefault &&
params.initial_show_state != ui::mojom::WindowShowState::kMinimized);
return Browser::DeprecatedCreateOwnedForTesting(params);
}
// TestBrowserWindow::TestLocationBar -----------------------------------------
OmniboxView* TestBrowserWindow::TestLocationBar::GetOmniboxView() {
return nullptr;
}
LocationBarTesting*
TestBrowserWindow::TestLocationBar::GetLocationBarForTesting() {
return nullptr;
}
LocationBarModel* TestBrowserWindow::TestLocationBar::GetLocationBarModel() {
return nullptr;
}
content::WebContents* TestBrowserWindow::TestLocationBar::GetWebContents() {
return nullptr;
}
// TestBrowserWindow ----------------------------------------------------------
TestBrowserWindow::TestBrowserWindow() = default;
TestBrowserWindow::~TestBrowserWindow() = default;
void TestBrowserWindow::Close() {
if (close_callback_) {
std::move(close_callback_).Run();
}
is_closed_ = true;
}
bool TestBrowserWindow::IsActive() const {
return is_active_;
}
ui::ZOrderLevel TestBrowserWindow::GetZOrderLevel() const {
return ui::ZOrderLevel::kNormal;
}
gfx::NativeWindow TestBrowserWindow::GetNativeWindow() const {
return native_window_;
}
bool TestBrowserWindow::IsOnCurrentWorkspace() const {
return true;
}
bool TestBrowserWindow::IsVisibleOnScreen() const {
return true;
}
void TestBrowserWindow::SetTopControlsShownRatio(
content::WebContents* web_contents,
float ratio) {}
bool TestBrowserWindow::DoBrowserControlsShrinkRendererSize(
const content::WebContents* contents) const {
return false;
}
ui::NativeTheme* TestBrowserWindow::GetNativeTheme() {
return nullptr;
}
const ui::ThemeProvider* TestBrowserWindow::GetThemeProvider() const {
return nullptr;
}
const ui::ColorProvider* TestBrowserWindow::GetColorProvider() const {
return ui::ColorProviderManager::Get().GetColorProviderFor(
ui::ColorProviderKey());
}
ui::ElementContext TestBrowserWindow::GetElementContext() {
return element_context_;
}
int TestBrowserWindow::GetTopControlsHeight() const {
return 0;
}
void TestBrowserWindow::SetTopControlsGestureScrollInProgress(
bool in_progress) {}
std::vector<StatusBubble*> TestBrowserWindow::GetStatusBubbles() {
return {};
}
gfx::Rect TestBrowserWindow::GetRestoredBounds() const {
return gfx::Rect();
}
ui::mojom::WindowShowState TestBrowserWindow::GetRestoredState() const {
return ui::mojom::WindowShowState::kDefault;
}
gfx::Rect TestBrowserWindow::GetBounds() const {
return gfx::Rect();
}
gfx::Size TestBrowserWindow::GetContentsSize() const {
return gfx::Size();
}
void TestBrowserWindow::SetContentsSize(const gfx::Size& size) {}
bool TestBrowserWindow::IsMaximized() const {
return false;
}
bool TestBrowserWindow::IsMinimized() const {
return is_minimized_;
}
bool TestBrowserWindow::ShouldHideUIForFullscreen() const {
return false;
}
bool TestBrowserWindow::GetCanResize() {
return false;
}
ui::mojom::WindowShowState TestBrowserWindow::GetWindowShowState() const {
return ui::mojom::WindowShowState::kDefault;
}
bool TestBrowserWindow::IsFullscreen() const {
return false;
}
bool TestBrowserWindow::IsFullscreenBubbleVisible() const {
return false;
}
bool TestBrowserWindow::IsForceFullscreen() const {
return false;
}
bool TestBrowserWindow::UpdateToolbarSecurityState() {
return false;
}
bool TestBrowserWindow::IsVisible() const {
return true;
}
LocationBar* TestBrowserWindow::GetLocationBar() const {
return const_cast<TestLocationBar*>(&location_bar_);
}
autofill::AutofillBubbleHandler* TestBrowserWindow::GetAutofillBubbleHandler() {
return &autofill_bubble_handler_;
}
ExtensionsContainer* TestBrowserWindow::GetExtensionsContainer() {
return nullptr;
}
bool TestBrowserWindow::PreHandleMouseEvent(const blink::WebMouseEvent& event) {
return false;
}
content::KeyboardEventProcessingResult
TestBrowserWindow::PreHandleKeyboardEvent(
const input::NativeWebKeyboardEvent& event) {
return content::KeyboardEventProcessingResult::NOT_HANDLED;
}
bool TestBrowserWindow::HandleKeyboardEvent(
const input::NativeWebKeyboardEvent& event) {
return false;
}
bool TestBrowserWindow::IsBookmarkBarVisible() const {
return false;
}
bool TestBrowserWindow::IsBookmarkBarAnimating() const {
return false;
}
bool TestBrowserWindow::IsTabStripEditable() const {
return is_tab_strip_editable_;
}
void TestBrowserWindow::SetTabStripNotEditableForTesting() {
is_tab_strip_editable_ = false;
}
bool TestBrowserWindow::IsToolbarVisible() const {
return false;
}
bool TestBrowserWindow::IsToolbarShowing() const {
return false;
}
bool TestBrowserWindow::IsLocationBarVisible() const {
return false;
}
bool TestBrowserWindow::IsBorderlessModeEnabled() const {
return false;
}
views::WebView* TestBrowserWindow::GetContentsWebView() {
return nullptr;
}
BrowserView* TestBrowserWindow::AsBrowserView() {
return nullptr;
}
ShowTranslateBubbleResult TestBrowserWindow::ShowTranslateBubble(
content::WebContents* contents,
translate::TranslateStep step,
const std::string& source_language,
const std::string& target_language,
translate::TranslateErrors error_type,
bool is_user_gesture) {
return ShowTranslateBubbleResult::SUCCESS;
}
void TestBrowserWindow::StartPartialTranslate(
const std::string& source_language,
const std::string& target_language,
const std::u16string& text_selection) {}
qrcode_generator::QRCodeGeneratorBubbleView*
TestBrowserWindow::ShowQRCodeGeneratorBubble(content::WebContents* contents,
const GURL& url,
bool show_back_button) {
return nullptr;
}
SharingDialog* TestBrowserWindow::ShowSharingDialog(
content::WebContents* web_contents,
SharingDialogData data) {
return nullptr;
}
#if !BUILDFLAG(IS_ANDROID)
sharing_hub::ScreenshotCapturedBubble*
TestBrowserWindow::ShowScreenshotCapturedBubble(content::WebContents* contents,
const gfx::Image& image) {
return nullptr;
}
#endif
send_tab_to_self::SendTabToSelfBubbleView*
TestBrowserWindow::ShowSendTabToSelfDevicePickerBubble(
content::WebContents* contents) {
return nullptr;
}
send_tab_to_self::SendTabToSelfBubbleView*
TestBrowserWindow::ShowSendTabToSelfPromoBubble(content::WebContents* contents,
bool show_signin_button) {
return nullptr;
}
#if BUILDFLAG(IS_CHROMEOS)
views::Button* TestBrowserWindow::GetSharingHubIconButton() {
return nullptr;
}
void TestBrowserWindow::ToggleMultitaskMenu() const {
return;
}
#else
sharing_hub::SharingHubBubbleView* TestBrowserWindow::ShowSharingHubBubble(
share::ShareAttempt attempt) {
return nullptr;
}
#endif // BUILDFLAG(IS_CHROMEOS)
bool TestBrowserWindow::IsDownloadShelfVisible() const {
return false;
}
DownloadShelf* TestBrowserWindow::GetDownloadShelf() {
return &download_shelf_;
}
views::View* TestBrowserWindow::GetTopContainer() {
return nullptr;
}
views::View* TestBrowserWindow::GetLensOverlayView() {
return nullptr;
}
DownloadBubbleUIController* TestBrowserWindow::GetDownloadBubbleUIController() {
return nullptr;
}
std::unique_ptr<FindBar> TestBrowserWindow::CreateFindBar() {
return nullptr;
}
web_modal::WebContentsModalDialogHost*
TestBrowserWindow::GetWebContentsModalDialogHost() {
return nullptr;
}
ExclusiveAccessContext* TestBrowserWindow::GetExclusiveAccessContext() {
return nullptr;
}
std::string TestBrowserWindow::GetWorkspace() const {
return workspace_;
}
bool TestBrowserWindow::IsVisibleOnAllWorkspaces() const {
return visible_on_all_workspaces_;
}
std::unique_ptr<content::EyeDropper> TestBrowserWindow::OpenEyeDropper(
content::RenderFrameHost* frame,
content::EyeDropperListener* listener) {
return nullptr;
}
void TestBrowserWindow::SetNativeWindow(gfx::NativeWindow window) {
native_window_ = window;
}
void TestBrowserWindow::SetCloseCallback(base::OnceClosure close_callback) {
close_callback_ = std::move(close_callback);
}
user_education::FeaturePromoController*
TestBrowserWindow::GetFeaturePromoControllerImpl() {
return feature_promo_controller_.get();
}
bool TestBrowserWindow::IsFeaturePromoQueued(
const base::Feature& iph_feature) const {
return feature_promo_controller_ &&
feature_promo_controller_->GetPromoStatus(iph_feature) ==
user_education::FeaturePromoStatus::kQueued;
}
bool TestBrowserWindow::IsFeaturePromoActive(
const base::Feature& iph_feature) const {
return feature_promo_controller_ &&
feature_promo_controller_->IsPromoActive(
iph_feature, user_education::FeaturePromoStatus::kContinued);
}
user_education::FeaturePromoResult TestBrowserWindow::CanShowFeaturePromo(
const base::Feature& iph_feature) const {
if (!feature_promo_controller_) {
return user_education::FeaturePromoResult::kBlockedByContext;
}
return feature_promo_controller_->CanShowPromo(iph_feature);
}
void TestBrowserWindow::MaybeShowFeaturePromo(
user_education::FeaturePromoParams params) {
if (!feature_promo_controller_) {
user_education::FeaturePromoController::PostShowPromoResult(
std::move(params.show_promo_result_callback),
user_education::FeaturePromoResult::kBlockedByContext);
return;
}
feature_promo_controller_->MaybeShowPromo(std::move(params));
}
void TestBrowserWindow::MaybeShowStartupFeaturePromo(
user_education::FeaturePromoParams params) {
if (feature_promo_controller_) {
feature_promo_controller_->MaybeShowStartupPromo(std::move(params));
}
}
bool TestBrowserWindow::AbortFeaturePromo(const base::Feature& iph_feature) {
return feature_promo_controller_ &&
feature_promo_controller_->EndPromo(
iph_feature, user_education::EndFeaturePromoReason::kAbortPromo);
}
user_education::FeaturePromoHandle
TestBrowserWindow::CloseFeaturePromoAndContinue(
const base::Feature& iph_feature) {
return feature_promo_controller_
? feature_promo_controller_->CloseBubbleAndContinuePromo(
iph_feature)
: user_education::FeaturePromoHandle();
}
bool TestBrowserWindow::NotifyFeaturePromoFeatureUsed(
const base::Feature& feature,
FeaturePromoFeatureUsedAction action) {
if (feature_promo_controller_ &&
action == FeaturePromoFeatureUsedAction::kClosePromoIfPresent) {
return feature_promo_controller_->EndPromo(
feature, user_education::EndFeaturePromoReason::kFeatureEngaged);
}
return false;
}
void TestBrowserWindow::NotifyAdditionalConditionEvent(const char* event_name) {
}
user_education::DisplayNewBadge TestBrowserWindow::MaybeShowNewBadgeFor(
const base::Feature& new_badge_feature) {
return user_education::DisplayNewBadge();
}
void TestBrowserWindow::NotifyNewBadgeFeatureUsed(
const base::Feature& feature) {}
bool TestBrowserWindow::IsTabModalPopupDeprecated() const {
return is_tab_modal_popup_deprecated_;
}
void TestBrowserWindow::SetIsTabModalPopupDeprecated(
bool is_tab_modal_popup_deprecated) {
is_tab_modal_popup_deprecated_ = is_tab_modal_popup_deprecated;
}
user_education::FeaturePromoController*
TestBrowserWindow::SetFeaturePromoController(
std::unique_ptr<user_education::FeaturePromoController>
feature_promo_controller) {
feature_promo_controller_ = std::move(feature_promo_controller);
return feature_promo_controller_.get();
}
// TestBrowserWindowOwner -----------------------------------------------------
TestBrowserWindowOwner::TestBrowserWindowOwner(
std::unique_ptr<TestBrowserWindow> window)
: window_(std::move(window)) {
BrowserList::AddObserver(this);
}
TestBrowserWindowOwner::~TestBrowserWindowOwner() {
BrowserList::RemoveObserver(this);
}
void TestBrowserWindowOwner::OnBrowserRemoved(Browser* browser) {
if (browser->window() == window_.get())
delete this;
}
|