Commit 9c194eb9 authored by jvoung@chromium.org's avatar jvoung@chromium.org

Move most of TestNaClBrowserDelegate to another file.

It was originally in nacl_file_host_unittest.
Move it to components/ and consider it the "base" test
version. In nacl_file_host_unittest, provide slimmer version
that overrides just what we need for the unittest.

This means that we can reuse the TestNaClBrowserDelegate for
other tests. E.g., I'll be adding one for checking that
the "abi-version" matters for translation caching, and
to test that we need to do a similar trick of having a 
Get/SetPnaclDirectory pair, so as not to modify the PNaCl
files inline.

It also means that we don't need to modify the test file
every time something is added to the NaClBrowserDelegate.


BUG=none
NOTRY=true
(already tried)

Review URL: https://codereview.chromium.org/51323004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233404 0039d316-1c4b-4281-b951-d872f2087c98
parent 1367bd63
...@@ -10,63 +10,20 @@ ...@@ -10,63 +10,20 @@
#include "base/test/scoped_path_override.h" #include "base/test/scoped_path_override.h"
#include "components/nacl/browser/nacl_browser.h" #include "components/nacl/browser/nacl_browser.h"
#include "components/nacl/common/nacl_browser_delegate.h" #include "components/nacl/common/nacl_browser_delegate.h"
#include "components/nacl/common/test_nacl_browser_delegate.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using nacl_file_host::PnaclCanOpenFile; using nacl_file_host::PnaclCanOpenFile;
class TestNaClBrowserDelegate : public NaClBrowserDelegate { class FileHostTestNaClBrowserDelegate : public TestNaClBrowserDelegate {
public: public:
FileHostTestNaClBrowserDelegate() {}
TestNaClBrowserDelegate() {}
virtual void ShowNaClInfobar(int render_process_id,
int render_view_id,
int error_id) OVERRIDE {
}
virtual bool DialogsAreSuppressed() OVERRIDE {
return false;
}
virtual bool GetCacheDirectory(base::FilePath* cache_dir) OVERRIDE {
return false;
}
virtual bool GetPluginDirectory(base::FilePath* plugin_dir) OVERRIDE {
return false;
}
virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) OVERRIDE { virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) OVERRIDE {
*pnacl_dir = pnacl_path_; *pnacl_dir = pnacl_path_;
return true; return true;
} }
virtual bool GetUserDirectory(base::FilePath* user_dir) OVERRIDE {
return false;
}
virtual std::string GetVersionString() const OVERRIDE {
return std::string();
}
virtual ppapi::host::HostFactory* CreatePpapiHostFactory(
content::BrowserPpapiHost* ppapi_host) OVERRIDE {
return NULL;
}
virtual bool MapUrlToLocalFilePath(const GURL& file_url,
bool use_blocking_api,
base::FilePath* file_path) OVERRIDE {
return false;
}
virtual void SetDebugPatterns(std::string debug_patterns) OVERRIDE {
}
virtual bool URLMatchesDebugPatterns(const GURL& manifest_url) OVERRIDE {
return false;
}
void SetPnaclDirectory(const base::FilePath& pnacl_dir) { void SetPnaclDirectory(const base::FilePath& pnacl_dir) {
pnacl_path_ = pnacl_dir; pnacl_path_ = pnacl_dir;
} }
...@@ -81,7 +38,7 @@ class NaClFileHostTest : public testing::Test { ...@@ -81,7 +38,7 @@ class NaClFileHostTest : public testing::Test {
virtual ~NaClFileHostTest(); virtual ~NaClFileHostTest();
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
nacl_browser_delegate_ = new TestNaClBrowserDelegate; nacl_browser_delegate_ = new FileHostTestNaClBrowserDelegate;
nacl::NaClBrowser::SetDelegate(nacl_browser_delegate_); nacl::NaClBrowser::SetDelegate(nacl_browser_delegate_);
} }
...@@ -90,12 +47,12 @@ class NaClFileHostTest : public testing::Test { ...@@ -90,12 +47,12 @@ class NaClFileHostTest : public testing::Test {
nacl::NaClBrowser::SetDelegate(NULL); nacl::NaClBrowser::SetDelegate(NULL);
} }
TestNaClBrowserDelegate* nacl_browser_delegate() { FileHostTestNaClBrowserDelegate* nacl_browser_delegate() {
return nacl_browser_delegate_; return nacl_browser_delegate_;
} }
private: private:
TestNaClBrowserDelegate* nacl_browser_delegate_; FileHostTestNaClBrowserDelegate* nacl_browser_delegate_;
DISALLOW_COPY_AND_ASSIGN(NaClFileHostTest); DISALLOW_COPY_AND_ASSIGN(NaClFileHostTest);
}; };
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
'nacl/loader/nacl_validation_db.h', 'nacl/loader/nacl_validation_db.h',
'nacl/loader/nacl_validation_query.cc', 'nacl/loader/nacl_validation_query.cc',
'nacl/loader/nacl_validation_query.h', 'nacl/loader/nacl_validation_query.h',
'nacl/common/test_nacl_browser_delegate.cc',
], ],
# TODO(gregoryd): consider switching NaCl to use Chrome OS defines # TODO(gregoryd): consider switching NaCl to use Chrome OS defines
'conditions': [ 'conditions': [
......
// Copyright 2013 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 "components/nacl/common/test_nacl_browser_delegate.h"
TestNaClBrowserDelegate::TestNaClBrowserDelegate() {}
TestNaClBrowserDelegate::~TestNaClBrowserDelegate() {}
void TestNaClBrowserDelegate::ShowNaClInfobar(int render_process_id,
int render_view_id,
int error_id) {}
bool TestNaClBrowserDelegate::DialogsAreSuppressed() {
return false;
}
bool TestNaClBrowserDelegate::GetCacheDirectory(base::FilePath* cache_dir) {
return false;
}
bool TestNaClBrowserDelegate::GetPluginDirectory(base::FilePath* plugin_dir) {
return false;
}
bool TestNaClBrowserDelegate::GetPnaclDirectory(base::FilePath* pnacl_dir) {
return false;
}
bool TestNaClBrowserDelegate::GetUserDirectory(base::FilePath* user_dir) {
return false;
}
std::string TestNaClBrowserDelegate::GetVersionString() const {
return std::string();
}
ppapi::host::HostFactory* TestNaClBrowserDelegate::CreatePpapiHostFactory(
content::BrowserPpapiHost* ppapi_host) {
return NULL;
}
bool TestNaClBrowserDelegate::MapUrlToLocalFilePath(const GURL& url,
bool use_blocking_api,
base::FilePath* file_path) {
return false;
}
void TestNaClBrowserDelegate::SetDebugPatterns(std::string debug_patterns) {}
bool TestNaClBrowserDelegate::URLMatchesDebugPatterns(
const GURL& manifest_url) {
return false;
}
// Copyright 2013 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 COMPONENTS_NACL_COMMON_TEST_NACL_BROWSER_DELEGATE_H_
#define COMPONENTS_NACL_COMMON_TEST_NACL_BROWSER_DELEGATE_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "components/nacl/common/nacl_browser_delegate.h"
// This is a base test implementation of NaClBrowserDelegate which
// does nothing. Individual tests can override the methods further.
// To use the test delegate:
//
// NaClBrowser::SetDelegate(new RefinedTestNaClBrowserDelegate);
//
// and
//
// NaClBrowser::SetDelegate(NULL); // frees the test delegate.
class TestNaClBrowserDelegate : public NaClBrowserDelegate {
public:
TestNaClBrowserDelegate();
virtual ~TestNaClBrowserDelegate();
virtual void ShowNaClInfobar(int render_process_id,
int render_view_id,
int error_id) OVERRIDE;
virtual bool DialogsAreSuppressed() OVERRIDE;
virtual bool GetCacheDirectory(base::FilePath* cache_dir) OVERRIDE;
virtual bool GetPluginDirectory(base::FilePath* plugin_dir) OVERRIDE;
virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) OVERRIDE;
virtual bool GetUserDirectory(base::FilePath* user_dir) OVERRIDE;
virtual std::string GetVersionString() const OVERRIDE;
virtual ppapi::host::HostFactory* CreatePpapiHostFactory(
content::BrowserPpapiHost* ppapi_host) OVERRIDE;
virtual bool MapUrlToLocalFilePath(const GURL& url,
bool use_blocking_api,
base::FilePath* file_path) OVERRIDE;
virtual void SetDebugPatterns(std::string debug_patterns) OVERRIDE;
virtual bool URLMatchesDebugPatterns(const GURL& manifest_url) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(TestNaClBrowserDelegate);
};
#endif // COMPONENTS_NACL_COMMON_TEST_NACL_BROWSER_DELEGATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment