Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: ios/web/public/test/web_test.mm

Issue 2666953003: [ios] Automatically fail any WebTest whose render process crashes. (Closed)
Patch Set: Add test. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/web/public/test/web_test.h" 5 #include "ios/web/public/test/web_test.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "ios/web/public/active_state_manager.h" 8 #include "ios/web/public/active_state_manager.h"
9 #include "ios/web/public/web_state/global_web_state_observer.h"
9 #import "ios/web/public/test/fakes/test_web_client.h" 10 #import "ios/web/public/test/fakes/test_web_client.h"
10 11
12 namespace {
Eugene But (OOO till 7-30) 2017/02/01 16:43:04 Drop this?
rohitrao (ping after 24h) 2017/02/01 18:22:59 Done.
13
14 } // namespace
15
11 namespace web { 16 namespace web {
12 17
13 WebTest::WebTest() : web_client_(base::WrapUnique(new TestWebClient)) {} 18 class RendererCrashObserver : public GlobalWebStateObserver {
19 public:
20 RendererCrashObserver() = default;
21 ~RendererCrashObserver() override = default;
22
23 void RenderProcessGone(WebState* web_state) override {
Eugene But (OOO till 7-30) 2017/02/01 16:43:04 Optional nit: Drop |web_state| argument
rohitrao (ping after 24h) 2017/02/01 18:22:59 GlobalWebStateObserver needs to pass this, so that
Eugene But (OOO till 7-30) 2017/02/01 18:41:45 Sorry, what I meant was: |void RenderProcessGone(W
24 FAIL() << "Renderer process died unexpectedly during the test";
25 }
26 };
27
28 WebTest::WebTest()
29 : web_client_(base::WrapUnique(new TestWebClient)) {
Eugene But (OOO till 7-30) 2017/02/01 16:43:04 Do we need web client? WebTestSuite already sets i
rohitrao (ping after 24h) 2017/02/01 18:22:59 Some tests call GetWebClient(), so leaving this in
30 renderer_crash_observer_ = base::MakeUnique<RendererCrashObserver>();
31 }
14 32
15 WebTest::~WebTest() {} 33 WebTest::~WebTest() {}
16 34
17 void WebTest::SetUp() { 35 void WebTest::SetUp() {
18 PlatformTest::SetUp(); 36 PlatformTest::SetUp();
19 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(true); 37 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(true);
20 } 38 }
21 39
22 void WebTest::TearDown() { 40 void WebTest::TearDown() {
23 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(false); 41 BrowserState::GetActiveStateManager(&browser_state_)->SetActive(false);
24 PlatformTest::TearDown(); 42 PlatformTest::TearDown();
25 } 43 }
26 44
27 TestWebClient* WebTest::GetWebClient() { 45 TestWebClient* WebTest::GetWebClient() {
28 return static_cast<TestWebClient*>(web_client_.Get()); 46 return static_cast<TestWebClient*>(web_client_.Get());
29 } 47 }
30 48
31 BrowserState* WebTest::GetBrowserState() { 49 BrowserState* WebTest::GetBrowserState() {
32 return &browser_state_; 50 return &browser_state_;
33 } 51 }
34 52
53 void WebTest::AllowRenderProcessCrashesDuringTesting(bool allow) {
54 if (allow) {
Eugene But (OOO till 7-30) 2017/02/01 16:43:04 Optional nit: Do you want to use ternary? renderer
rohitrao (ping after 24h) 2017/02/01 18:22:59 If you don't feel strongly, I'll keep this as-is.
55 renderer_crash_observer_ = nullptr;
56 } else {
57 renderer_crash_observer_ = base::MakeUnique<RendererCrashObserver>();
58 }
59 }
60
35 } // namespace web 61 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698