forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweblayer_browser_test_utils.cc
63 lines (51 loc) · 2 KB
/
weblayer_browser_test_utils.cc
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
// Copyright 2019 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 "weblayer/test/weblayer_browser_test_utils.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "url/gurl.h"
#include "weblayer/browser/tab_impl.h"
#include "weblayer/public/navigation_controller.h"
#include "weblayer/public/tab.h"
#include "weblayer/shell/browser/shell.h"
#include "weblayer/test/test_navigation_observer.h"
namespace weblayer {
namespace {
// Navigates to |url| in |shell| and waits for |event| to occur.
void NavigateAndWaitForEvent(const GURL& url,
Shell* shell,
TestNavigationObserver::NavigationEvent event) {
TestNavigationObserver test_observer(url, event, shell);
shell->tab()->GetNavigationController()->Navigate(url);
test_observer.Wait();
}
} // namespace
void NavigateAndWaitForCompletion(const GURL& url, Shell* shell) {
NavigateAndWaitForEvent(url, shell,
TestNavigationObserver::NavigationEvent::Completion);
}
void NavigateAndWaitForFailure(const GURL& url, Shell* shell) {
NavigateAndWaitForEvent(url, shell,
TestNavigationObserver::NavigationEvent::Failure);
}
base::Value ExecuteScript(Shell* shell,
const std::string& script,
bool use_separate_isolate) {
base::Value final_result;
base::RunLoop run_loop;
shell->tab()->ExecuteScript(
base::ASCIIToUTF16(script), use_separate_isolate,
base::BindLambdaForTesting(
[&run_loop, &final_result](base::Value result) {
final_result = std::move(result);
run_loop.Quit();
}));
run_loop.Run();
return final_result;
}
const base::string16& GetTitle(Shell* shell) {
TabImpl* tab_impl = static_cast<TabImpl*>(shell->tab());
return tab_impl->web_contents()->GetTitle();
}
} // namespace weblayer