chromium/chrome/browser/apps/platform_apps/api/media_galleries/media_galleries_watch_apitest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// MediaGalleries gallery watch API browser tests.

#include <memory>

#include "base/files/file_path.h"
#include "base/files/file_path_watcher.h"
#include "base/files/file_util.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/media_galleries/media_file_system_registry.h"
#include "chrome/browser/media_galleries/media_galleries_preferences.h"
#include "chrome/browser/media_galleries/media_galleries_test_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"

namespace {

// Id of test extension from
// chrome/test/data/extensions/api_test/|kTestExtensionPath|
const char kTestExtensionId[] =;
const char kTestExtensionPath[] =;

// JS commands.
const char kGetMediaFileSystemsCmd[] =;
const char kSetupWatchOnValidGalleriesCmd[] =;
const char kSetupWatchOnUnlistenedValidGalleriesCmd[] =;
const char kAddGalleryChangedListenerCmd[] =;
const char kAddCheckingGalleryChangedListenerCmd[] =;
const char kRemoveGalleryChangedListenerCmd[] =;
const char kRemoveGalleryWatchCmd[] =;
const char kSetupWatchOnInvalidGalleryCmd[] =;

// And JS reply messages.
const char kAddGalleryWatchOK[] =;
const char kGetMediaFileSystemsCallbackOK[] =;
const char kGetMediaFileSystemsOK[] =;
const char kAddGalleryChangedListenerOK[] =;
const char kRemoveGalleryChangedListenerOK[] =;
const char kRemoveGalleryWatchOK[] =;
const char kOnGalleryChangedCheckingOK[] =;

// Test reply messages.
const char kAddGalleryWatchRequestFailed[] =;
const char kAddGalleryWatchRequestRuntimeError[] =;
const char kAddGalleryWatchRequestSucceeded[] =;
const char kGalleryChangedEventReceived[] =;

}  // namespace

///////////////////////////////////////////////////////////////////////////////
//                 MediaGalleriesGalleryWatchApiTest                         //
///////////////////////////////////////////////////////////////////////////////

class MediaGalleriesGalleryWatchApiTest : public extensions::ExtensionApiTest {};

// TODO(crbug.com/40748275): Re-enable. Flaky on Linux and Windows.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_BasicGalleryWatch
#else
#define MAYBE_BasicGalleryWatch
#endif
IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest,
                       MAYBE_BasicGalleryWatch) {}

// TODO(crbug.com/40671492): Flaky on Linux and Windows.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_CorrectResponseOnModifyingWatchedGallery
#else
#define MAYBE_CorrectResponseOnModifyingWatchedGallery
#endif
IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest,
                       MAYBE_CorrectResponseOnModifyingWatchedGallery) {}

// Test is flaky on windows and linux: crbug.com/1150017.
// TODO(crbug.com/40118868): Revisit once build flag switch of lacros-chrome is
// complete.
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
#define MAYBE_RemoveListenerAndModifyGallery
#else
#define MAYBE_RemoveListenerAndModifyGallery
#endif
IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest,
                       MAYBE_RemoveListenerAndModifyGallery) {}

IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest,
                       SetupGalleryWatchWithoutListeners) {}

IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest,
                       SetupGalleryChangedListenerWithoutWatchers) {}

IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest,
                       SetupWatchOnInvalidGallery) {}