Skip to content

Commit 96efa72

Browse files
committed
fix unit tests
Signed-off-by: Vadym Struts <vstruts@brave.com>
1 parent bac9919 commit 96efa72

File tree

6 files changed

+302
-57
lines changed

6 files changed

+302
-57
lines changed

browser/psst/BUILD.gn

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ static_library("psst") {
2626
"//brave/components/psst/browser/core",
2727
"//brave/components/psst/common",
2828
"//chrome/browser/content_settings:content_settings_factory",
29-
"//chrome/browser/profiles",
30-
"//components/content_settings/core/browser",
31-
"//components/permissions",
32-
"//components/infobars/core",
3329
"//chrome/browser/infobars",
30+
"//chrome/browser/profiles",
3431
"//chrome/browser/ui/webui",
32+
"//components/content_settings/core/browser",
3533
"//components/infobars/content",
34+
"//components/infobars/core",
35+
"//components/permissions",
3636
"//ui/web_dialogs",
3737
]
3838
}
@@ -64,6 +64,7 @@ source_set("browser_tests") {
6464

6565
deps = [
6666
"//base",
67+
"//brave/browser/psst",
6768
"//brave/components/brave_shields/content/browser",
6869
"//brave/components/cosmetic_filters/browser",
6970
"//brave/components/psst/browser/content",
@@ -72,11 +73,10 @@ source_set("browser_tests") {
7273
"//brave/components/psst/common",
7374
"//chrome/test:test_support",
7475
"//components/component_updater:test_support",
76+
"//components/infobars/content",
7577
"//content/test:test_support",
7678
"//net:test_support",
7779
"//url",
78-
"//brave/browser/psst",
79-
"//components/infobars/content",
8080
]
8181

8282
if (is_android) {

browser/psst/psst_ui_delegate_impl.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ PsstUiDelegateImpl::PsstUiDelegateImpl(
5252
}
5353
PsstUiDelegateImpl::~PsstUiDelegateImpl() = default;
5454

55-
void PsstUiDelegateImpl::Show(
56-
const url::Origin& origin,
57-
PsstWebsiteSettings dialog_data,
58-
const std::string& site_name,
59-
base::ListValue tasks,
60-
PsstTabWebContentsObserver::ConsentCallback apply_changes_callback) {
55+
void PsstUiDelegateImpl::Show(const url::Origin& origin,
56+
PsstWebsiteSettings dialog_data,
57+
const std::string& site_name,
58+
base::ListValue tasks,
59+
ConsentCallback apply_changes_callback) {
6160
auto psst_settings = psst_settings_service_->GetPsstWebsiteSettings(
6261
origin, dialog_data.user_id);
6362

browser/psst/psst_ui_delegate_impl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class PsstUiDelegateImpl : public PsstTabWebContentsObserver::PsstUiDelegate {
6161
PsstWebsiteSettings dialog_data,
6262
const std::string& site_name,
6363
base::ListValue tasks,
64-
PsstTabWebContentsObserver::ConsentCallback apply_changes_callback)
65-
override;
64+
ConsentCallback apply_changes_callback) override;
6665

6766
void UpdateTasks(long progress,
6867
const std::vector<PolicyTask>& applied_tasks,
@@ -80,7 +79,7 @@ class PsstUiDelegateImpl : public PsstTabWebContentsObserver::PsstUiDelegate {
8079
std::optional<PsstWebsiteSettings> dialog_data_;
8180
std::optional<url::Origin> origin_;
8281
std::optional<base::ListValue> tasks_;
83-
PsstTabWebContentsObserver::ConsentCallback apply_changes_callback_;
82+
ConsentCallback apply_changes_callback_;
8483
raw_ptr<PsstSettingsService> psst_settings_service_ = nullptr;
8584
base::ObserverList<Observer> observer_list_;
8685
base::WeakPtrFactory<PsstUiDelegateImpl> weak_ptr_factory_{this};

components/psst/browser/content/psst_tab_web_contents_observer.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ void PsstTabWebContentsObserver::NavigationEntryCommitted(
203203
CHECK(load_details.entry);
204204
if (!load_details.is_navigation_to_different_page() ||
205205
!load_details.entry->GetURL().SchemeIsHTTPOrHTTPS() ||
206-
load_details.entry->IsRestored()) {
206+
load_details.entry->IsRestored() ||
207+
!prefs_->GetBoolean(prefs::kPsstEnabled)) {
207208
return;
208209
}
209210

@@ -367,6 +368,7 @@ void PsstTabWebContentsObserver::OnPolicyScriptResult(
367368
timeout_timer_.Stop();
368369

369370
if (!script_result.is_dict()) {
371+
ui_delegate_->UpdateTasks(100, {}, mojom::PsstStatus::kFailed);
370372
return;
371373
}
372374

components/psst/browser/content/psst_tab_web_contents_observer.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ class PsstTabWebContentsObserver : public content::WebContentsObserver {
3333
using InjectScriptCallback = base::RepeatingCallback<void(
3434
const std::string&,
3535
PsstTabWebContentsObserver::InsertScriptInPageCallback)>;
36-
using ConsentCallback =
37-
base::OnceCallback<void(const std::vector<std::string>& disabled_checks)>;
3836

3937
// Delegate interface for UI-related actions. This class is responsible for
4038
// facilitating communication with the consent dialog, ensuring that the UI
4139
// reflects the current state accurately.
4240
class PsstUiDelegate {
4341
public:
42+
using ConsentCallback = base::OnceCallback<void(
43+
const std::vector<std::string>& disabled_checks)>;
44+
4445
virtual ~PsstUiDelegate() = default;
4546
// Show the consent dialog to the user with the provided data.
4647
virtual void Show(const url::Origin& origin,
@@ -76,6 +77,8 @@ class PsstTabWebContentsObserver : public content::WebContentsObserver {
7677

7778
private:
7879
friend class PsstTabWebContentsObserverUnitTestBase;
80+
FRIEND_TEST_ALL_PREFIXES(PsstTabWebContentsObserverUnitTest,
81+
ShouldNotProcessRestoredNavigationEntry);
7982

8083
PsstTabWebContentsObserver(content::WebContents* web_contents,
8184
PsstRuleRegistry* registry,

0 commit comments

Comments
 (0)