Skip to content

Commit

Permalink
Change from Mock to Fake for KioskAppLauncher
Browse files Browse the repository at this point in the history
This change will a) make the tests follow a clearer logical structure of doSomething first, then validate the expected effect. b) it allows to prepare for the future case where app_launcher_ can be null before a certain operation is run, so we cannot set expectations on that object yet.

Bug: b:256596278
Test: KioskLaunchControllerTest
Change-Id: I69f29dbda0eff4ae3e95d4a00096df478c7c431e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4188537
Reviewed-by: Roland Bock <rbock@google.com>
Reviewed-by: Jeroen Dhollander <jeroendh@google.com>
Commit-Queue: Ben Franz <bfranz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1097307}
  • Loading branch information
bfranz authored and Chromium LUCI CQ committed Jan 26, 2023
1 parent 9d69fd2 commit b997013
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 115 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/ash/BUILD.gn
Expand Up @@ -4231,10 +4231,10 @@ static_library("test_support") {
"app_list/test/test_app_list_controller_delegate.h",
"app_mode/fake_cws.cc",
"app_mode/fake_cws.h",
"app_mode/fake_kiosk_app_launcher.cc",
"app_mode/fake_kiosk_app_launcher.h",
"app_mode/test_kiosk_extension_builder.cc",
"app_mode/test_kiosk_extension_builder.h",
"app_mode/web_app/mock_web_kiosk_app_launcher.cc",
"app_mode/web_app/mock_web_kiosk_app_launcher.h",
"arc/extensions/fake_arc_support.cc",
"arc/extensions/fake_arc_support.h",
"arc/tracing/arc_app_performance_tracing_test_helper.cc",
Expand Down
36 changes: 36 additions & 0 deletions chrome/browser/ash/app_mode/fake_kiosk_app_launcher.cc
@@ -0,0 +1,36 @@
// Copyright 2023 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/browser/ash/app_mode/fake_kiosk_app_launcher.h"
#include "chrome/browser/ash/app_mode/kiosk_app_launcher.h"

namespace ash {

FakeKioskAppLauncher::FakeKioskAppLauncher() = default;
FakeKioskAppLauncher::~FakeKioskAppLauncher() = default;

void FakeKioskAppLauncher::AddObserver(KioskAppLauncher::Observer* observer) {
observers_.AddObserver(observer);
}

void FakeKioskAppLauncher::RemoveObserver(
KioskAppLauncher::Observer* observer) {
observers_.RemoveObserver(observer);
}

void FakeKioskAppLauncher::Initialize() {
++initialize_called_;
}

void FakeKioskAppLauncher::ContinueWithNetworkReady() {
++continue_with_network_ready_called_;
}

void FakeKioskAppLauncher::LaunchApp() {
++launch_app_called_;
}

void FakeKioskAppLauncher::RestartLauncher() {}

} // namespace ash
49 changes: 49 additions & 0 deletions chrome/browser/ash/app_mode/fake_kiosk_app_launcher.h
@@ -0,0 +1,49 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_APP_MODE_FAKE_KIOSK_APP_LAUNCHER_H_
#define CHROME_BROWSER_ASH_APP_MODE_FAKE_KIOSK_APP_LAUNCHER_H_

#include "chrome/browser/ash/app_mode/kiosk_app_launcher.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace ash {

class FakeKioskAppLauncher : public KioskAppLauncher {
public:
FakeKioskAppLauncher();
~FakeKioskAppLauncher() override;

// `KioskAppLauncher`:
void AddObserver(KioskAppLauncher::Observer* observer) override;
void RemoveObserver(KioskAppLauncher::Observer* observer) override;
void Initialize() override;
void ContinueWithNetworkReady() override;
void LaunchApp() override;
void RestartLauncher() override;

void ResetAppLaunched();

bool IsInitialized() const { return initialize_called_ > 0; }
bool HasAppLaunched() const { return launch_app_called_ > 0; }
bool HasContinueWithNetworkReadyBeenCalled() const {
return continue_with_network_ready_called_ > 0;
}
int initialize_called() { return initialize_called_; }
int launch_app_called() { return launch_app_called_; }
int continue_with_network_ready_called() {
return continue_with_network_ready_called_;
}

KioskAppLauncher::ObserverList& observers() { return observers_; }

private:
KioskAppLauncher::ObserverList observers_;
int initialize_called_ = 0;
int launch_app_called_ = 0;
int continue_with_network_ready_called_ = 0;
};

} // namespace ash

#endif // CHROME_BROWSER_ASH_APP_MODE_FAKE_KIOSK_APP_LAUNCHER_H_
34 changes: 0 additions & 34 deletions chrome/browser/ash/app_mode/web_app/mock_web_kiosk_app_launcher.cc

This file was deleted.

36 changes: 0 additions & 36 deletions chrome/browser/ash/app_mode/web_app/mock_web_kiosk_app_launcher.h

This file was deleted.

0 comments on commit b997013

Please sign in to comment.