forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper class to register/unregister WebClient.
ScopedTestingWebClient register a WebClient at initialisation and unregister at destruction, restoring the previous WebClient. This class also assert if the registered WebClient has been changed by the time the destructor is reached. Port all unit tests to use ScopedTestingWebClient when installing a WebClient instead of using SetWebClient to avoid mistakes. BUG=None Review URL: https://codereview.chromium.org/1534823003 Cr-Commit-Position: refs/heads/master@{#365840}
- Loading branch information
Showing
16 changed files
with
150 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2015 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 "ios/web/public/test/scoped_testing_web_client.h" | ||
|
||
#include "base/logging.h" | ||
#include "ios/web/public/web_client.h" | ||
|
||
namespace web { | ||
|
||
ScopedTestingWebClient::ScopedTestingWebClient(scoped_ptr<WebClient> web_client) | ||
: web_client_(std::move(web_client)), original_web_client_(GetWebClient()) { | ||
SetWebClient(web_client_.get()); | ||
} | ||
|
||
ScopedTestingWebClient::~ScopedTestingWebClient() { | ||
DCHECK_EQ(GetWebClient(), web_client_.get()); | ||
SetWebClient(original_web_client_); | ||
} | ||
|
||
WebClient* ScopedTestingWebClient::Get() { | ||
return web_client_.get(); | ||
} | ||
|
||
} // namespace web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2015 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. | ||
|
||
#ifndef IOS_WEB_PUBLIC_TEST_SCOPED_TESTING_WEB_CLIENT_H_ | ||
#define IOS_WEB_PUBLIC_TEST_SCOPED_TESTING_WEB_CLIENT_H_ | ||
|
||
#include "base/macros.h" | ||
#include "base/memory/scoped_ptr.h" | ||
|
||
namespace web { | ||
|
||
class WebClient; | ||
|
||
// Helper class to register a WebClient during unit testing. | ||
class ScopedTestingWebClient { | ||
public: | ||
explicit ScopedTestingWebClient(scoped_ptr<WebClient> web_client); | ||
~ScopedTestingWebClient(); | ||
|
||
WebClient* Get(); | ||
|
||
private: | ||
scoped_ptr<WebClient> web_client_; | ||
WebClient* original_web_client_; | ||
}; | ||
|
||
} // namespace web | ||
|
||
#endif // IOS_WEB_PUBLIC_TEST_SCOPED_TESTING_WEB_CLIENT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.