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

Unified Diff: chrome/browser/chromeos/customization/customization_wallpaper_downloader_browsertest.cc

Issue 2413503002: Cleanup mojo Wallpaper interfaces for mash. (Closed)
Patch Set: Sync and rebase; do *not* use mojo in classic ash. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/customization/customization_wallpaper_downloader_browsertest.cc
diff --git a/chrome/browser/chromeos/customization/customization_wallpaper_downloader_browsertest.cc b/chrome/browser/chromeos/customization/customization_wallpaper_downloader_browsertest.cc
index db2dcc8af1d6fcf05b1d167af6e93c307731c343..42b5f875a06308c20da9651dcd4864738ad3f457 100644
--- a/chrome/browser/chromeos/customization/customization_wallpaper_downloader_browsertest.cc
+++ b/chrome/browser/chromeos/customization/customization_wallpaper_downloader_browsertest.cc
@@ -6,7 +6,6 @@
#include <vector>
-#include "ash/common/wallpaper/wallpaper_controller.h"
#include "ash/common/wm_shell.h"
#include "base/command_line.h"
#include "base/files/scoped_temp_dir.h"
@@ -17,13 +16,16 @@
#include "chrome/browser/chromeos/customization/customization_wallpaper_downloader.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_test_utils.h"
+#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chromeos/chromeos_switches.h"
+#include "content/public/common/service_manager_connection.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_impl.h"
+#include "services/shell/public/cpp/connector.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
@@ -86,6 +88,40 @@ class TestWallpaperObserver : public WallpaperManager::Observer {
DISALLOW_COPY_AND_ASSIGN(TestWallpaperObserver);
};
+// The callback used to retrieve the wallpaper from ash.
+void GetWallpaperCallback(gfx::ImageSkia* image_out,
+ wallpaper::WallpaperLayout* layout_out,
+ base::Closure callback,
+ const SkBitmap& wallpaper,
+ wallpaper::WallpaperLayout layout) {
+ *image_out = gfx::ImageSkia::CreateFrom1xBitmap(wallpaper);
+ *layout_out = layout;
+ callback.Run();
+}
+
+// A helper to synchronously get the wallpaper from ash.
+void GetWallpaper(gfx::ImageSkia* image_out,
+ wallpaper::WallpaperLayout* layout_out) {
+ auto connection = content::ServiceManagerConnection::GetForProcess();
+ auto connector = connection ? connection->GetConnector() : nullptr;
James Cook 2016/10/14 21:58:02 As before, I don't think these types are complex e
msw 2016/10/17 22:22:47 I reverted these test changes.
+ if (!connector)
+ return;
+
+ ash::mojom::WallpaperControllerPtr wallpaper_controller;
+ // Under mash the WallpaperController interface is in the ash process. In
James Cook 2016/10/14 21:58:02 So does this test no longer exercise the classic a
msw 2016/10/17 22:22:48 I restored the classic ash code path here.
+ // classic ash we provide it to ourself.
+ if (chrome::IsRunningInMash()) {
+ connector->ConnectToInterface("service:ash", &wallpaper_controller);
+ } else {
+ connector->ConnectToInterface("service:content_browser",
+ &wallpaper_controller);
+ }
+ base::RunLoop run_loop;
+ wallpaper_controller->GetWallpaper(base::Bind(
+ &GetWallpaperCallback, image_out, layout_out, run_loop.QuitClosure()));
+ run_loop.Run();
+}
+
} // namespace
// This is helper class for net::FakeURLFetcherFactory.
@@ -220,25 +256,14 @@ class WallpaperImageFetcherFactory {
class CustomizationWallpaperDownloaderBrowserTest
: public InProcessBrowserTest {
public:
- CustomizationWallpaperDownloaderBrowserTest()
- : controller_(NULL),
- local_state_(NULL) {
- }
-
+ CustomizationWallpaperDownloaderBrowserTest() {}
~CustomizationWallpaperDownloaderBrowserTest() override {}
- void SetUpOnMainThread() override {
- controller_ = ash::WmShell::Get()->wallpaper_controller();
- local_state_ = g_browser_process->local_state();
- }
-
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
}
- void TearDownOnMainThread() override { controller_ = NULL; }
-
protected:
void CreateCmdlineWallpapers() {
cmdline_wallpaper_dir_.reset(new base::ScopedTempDir);
@@ -247,8 +272,6 @@ class CustomizationWallpaperDownloaderBrowserTest
*cmdline_wallpaper_dir_, &wallpaper_manager_command_line_);
}
- ash::WallpaperController* controller_;
- PrefService* local_state_;
std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_;
// Directory created by CreateCmdlineWallpapersAndSetFlags() to store default
@@ -264,10 +287,12 @@ IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
CreateCmdlineWallpapers();
WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
- EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
- controller_->GetWallpaper(),
- wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
+ gfx::ImageSkia image;
+ wallpaper::WallpaperLayout layout = wallpaper::NUM_WALLPAPER_LAYOUT;
+ GetWallpaper(&image, &layout);
+ EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
+ image, wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
WallpaperImageFetcherFactory url_factory(
GURL(kOEMWallpaperURL),
wallpaper_manager_test_utils::kWallpaperSize,
@@ -282,9 +307,9 @@ IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
customization->LoadManifestFromString(std::string(kServicesManifest)));
observer.WaitForWallpaperAnimationFinished();
+ GetWallpaper(&image, &layout);
EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
- controller_->GetWallpaper(),
- wallpaper_manager_test_utils::kCustomWallpaperColor));
+ image, wallpaper_manager_test_utils::kCustomWallpaperColor));
EXPECT_EQ(1U, url_factory.num_attempts());
}
@@ -293,9 +318,12 @@ IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
CreateCmdlineWallpapers();
WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
+
+ gfx::ImageSkia image;
+ wallpaper::WallpaperLayout layout = wallpaper::NUM_WALLPAPER_LAYOUT;
+ GetWallpaper(&image, &layout);
EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
- controller_->GetWallpaper(),
- wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
+ image, wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
WallpaperImageFetcherFactory url_factory(
GURL(kOEMWallpaperURL),
@@ -311,9 +339,9 @@ IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
customization->LoadManifestFromString(std::string(kServicesManifest)));
observer.WaitForWallpaperAnimationFinished();
+ GetWallpaper(&image, &layout);
EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
- controller_->GetWallpaper(),
- wallpaper_manager_test_utils::kCustomWallpaperColor));
+ image, wallpaper_manager_test_utils::kCustomWallpaperColor));
EXPECT_EQ(2U, url_factory.num_attempts());
}

Powered by Google App Engine
This is Rietveld 408576698