Allow overriding WebUIFactory when test flag is set.
In order to allow mocking function calls as soon as possible (before any javascript is
run), we create a factory capable of registering overrides per-host.
BUG=82437R=estade@chromium.org
TEST=browser_tests --gtest_filter=TestChromeWebUIFactoryTest.*
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86764
Evan, You mentioned refactoring the ChomeWebUIFactory recently. The hope of this new class is to ...
9 years, 7 months ago
(2011-05-24 05:57:05 UTC)
#1
Evan,
You mentioned refactoring the ChomeWebUIFactory recently. The hope of this new
class is to provide an override mechanism which is only used for test cases.
Evan Stade
just nits http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/chrome_web_ui_factory.cc File chrome/browser/ui/webui/chrome_web_ui_factory.cc (right): http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/chrome_web_ui_factory.cc#newcode224 chrome/browser/ui/webui/chrome_web_ui_factory.cc:224: struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { explicitly ...
9 years, 7 months ago
(2011-05-24 17:25:59 UTC)
#2
some nits below: (whoops, just realized I was using the wrong acct) http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/chrome_web_ui_factory.cc File chrome/browser/ui/webui/chrome_web_ui_factory.cc ...
9 years, 7 months ago
(2011-05-24 18:00:06 UTC)
#3
Added comment. http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/chrome_web_ui_factory.cc File chrome/browser/ui/webui/chrome_web_ui_factory.cc (right): http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/chrome_web_ui_factory.cc#newcode224 chrome/browser/ui/webui/chrome_web_ui_factory.cc:224: struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { As ...
9 years, 7 months ago
(2011-05-25 18:29:42 UTC)
#5
Added comment.
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/chro...
File chrome/browser/ui/webui/chrome_web_ui_factory.cc (right):
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/chro...
chrome/browser/ui/webui/chrome_web_ui_factory.cc:224: struct
PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> {
As discussed in email thread, my main argument for doing it here in traits
instead of in GetInstance() is that the if condition will be done exactly once
(when the singleton doesn't exist) rather than with every call to GetInstance().
While the time savings may be minimal, it is conceptually what I want. I'll
add a comment.
On 2011/05/24 18:00:06, thestig wrote:
> Do you need this template? Why can't you just do the following in
GetInstance()
> ?
>
> if (CommandLine::ForCurrentProcess()->HasSwitch(some_flag))
> return Singleton<TestChromeWebUIFactory>::get();
> else
> return Singleton<ChromeWebUIFactory>::get();
Evan Stade
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc File chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc (right): http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc#newcode46 chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc:46: GURL(kChromeTestChromeWebUIFactory).host()); no, I meant why is everything within SetUp ...
9 years, 7 months ago
(2011-05-25 18:49:03 UTC)
#6
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc File chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc (right): http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc#newcode46 chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc:46: GURL(kChromeTestChromeWebUIFactory).host()); If I move the add/remove to the method, ...
9 years, 7 months ago
(2011-05-25 21:02:55 UTC)
#7
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test...
File chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc (right):
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test...
chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc:46:
GURL(kChromeTestChromeWebUIFactory).host());
If I move the add/remove to the method, then I'm not registered early enough to
catch cases where I'm called unexpectedly.
To prove this empirically, I added AddFactoryOverride("", &mock_provider_) both
here and in the test, and only caught the spurious call to the mock when the
code was in the SetUpInProcessBrowserTestFixture().
On 2011/05/25 18:49:04, Evan Stade wrote:
> no, I meant why is everything within SetUp and TearDown not just inside the
test
> itself?
>
> re: GURL as global constant: that's why non-PODs should never be global.
Evan Stade
lgtm -- Evan Stade On Wed, May 25, 2011 at 2:02 PM, <scr@chromium.org> wrote: > ...
9 years, 7 months ago
(2011-05-25 21:14:13 UTC)
#8
lgtm
-- Evan Stade
On Wed, May 25, 2011 at 2:02 PM, <scr@chromium.org> wrote:
>
>
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test...
> File chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc
> (right):
>
>
http://codereview.chromium.org/6992019/diff/5001/chrome/browser/ui/webui/test...
> chrome/browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc:46:
> GURL(kChromeTestChromeWebUIFactory).host());
> If I move the add/remove to the method, then I'm not registered early
> enough to catch cases where I'm called unexpectedly.
>
> To prove this empirically, I added AddFactoryOverride("",
> &mock_provider_) both here and in the test, and only caught the spurious
> call to the mock when the code was in the
> SetUpInProcessBrowserTestFixture().
>
> On 2011/05/25 18:49:04, Evan Stade wrote:
>>
>> no, I meant why is everything within SetUp and TearDown not just
>
> inside the test
>>
>> itself?
>
>> re: GURL as global constant: that's why non-PODs should never be
>
> global.
>
> http://codereview.chromium.org/6992019/
>
Lei Zhang
LGTM http://codereview.chromium.org/6992019/diff/19/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc File chrome/browser/ui/webui/test_chrome_web_ui_factory.cc (right): http://codereview.chromium.org/6992019/diff/19/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc#newcode7 chrome/browser/ui/webui/test_chrome_web_ui_factory.cc:7: #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" nit: You don't need to include ...
9 years, 7 months ago
(2011-05-25 21:21:18 UTC)
#9
Issue 6992019: Allow overriding WebUIFactory when test flag is set.
(Closed)
Created 9 years, 7 months ago by Sheridan Rawlins
Modified 9 years, 6 months ago
Reviewers: Evan Stade, Lei Zhang (Do not use), Lei Zhang, commit-bot: I haz the power
Base URL: svn://svn.chromium.org/chrome/trunk/src
Comments: 28