| Index: gpu/command_buffer/service/texture_manager_unittest.cc
 | 
| diff --git a/gpu/command_buffer/service/texture_manager_unittest.cc b/gpu/command_buffer/service/texture_manager_unittest.cc
 | 
| index ad82cf301ecdae6530992f61bfee653971e6e8c2..7f3f41e1c8374a2fb8ad9912b0336e24383eb259 100644
 | 
| --- a/gpu/command_buffer/service/texture_manager_unittest.cc
 | 
| +++ b/gpu/command_buffer/service/texture_manager_unittest.cc
 | 
| @@ -12,7 +12,9 @@
 | 
|  
 | 
|  #include "base/command_line.h"
 | 
|  #include "base/macros.h"
 | 
| +#include "base/strings/string_number_conversions.h"
 | 
|  #include "gpu/command_buffer/client/client_test_helper.h"
 | 
| +#include "gpu/command_buffer/service/context_state.h"
 | 
|  #include "gpu/command_buffer/service/error_state_mock.h"
 | 
|  #include "gpu/command_buffer/service/feature_info.h"
 | 
|  #include "gpu/command_buffer/service/framebuffer_manager.h"
 | 
| @@ -24,6 +26,7 @@
 | 
|  #include "gpu/command_buffer/service/mocks.h"
 | 
|  #include "gpu/command_buffer/service/service_discardable_manager.h"
 | 
|  #include "gpu/command_buffer/service/test_helper.h"
 | 
| +#include "gpu/config/gpu_switches.h"
 | 
|  #include "testing/gtest/include/gtest/gtest.h"
 | 
|  #include "ui/gl/gl_image_stub.h"
 | 
|  #include "ui/gl/gl_mock.h"
 | 
| @@ -645,6 +648,82 @@ TEST_F(TextureManagerTest, AlphaLuminanceCoreProfileEmulation) {
 | 
|    manager.RemoveTexture(kClientId);
 | 
|  }
 | 
|  
 | 
| +// Test texture base level is set before texImage2D when workaround
 | 
| +// RESET_TEXIMAGE2D_BASE_LEVEL is enabled
 | 
| +TEST_F(TextureManagerTest, SetTextureBaseLevelBeforeTexImage2D) {
 | 
| +  GpuDriverBugWorkarounds gpu_driver_bug_workaround;
 | 
| +  gpu_driver_bug_workaround.reset_teximage2d_base_level = true;
 | 
| +  feature_info_ = new FeatureInfo(gpu_driver_bug_workaround);
 | 
| +
 | 
| +  SetupFeatureInfo("", "OpenGL ES 3.0", CONTEXT_TYPE_OPENGLES3);
 | 
| +  TestHelper::SetupTextureManagerInitExpectations(gl_.get(), true, true, false,
 | 
| +                                                  "", kUseDefaultTextures);
 | 
| +  TextureManager manager(nullptr, feature_info_.get(), kMaxTextureSize,
 | 
| +                         kMaxCubeMapTextureSize, kMaxRectangleTextureSize,
 | 
| +                         kMax3DTextureSize, kMaxArrayTextureLayers,
 | 
| +                         kUseDefaultTextures, nullptr, &discardable_manager_);
 | 
| +  manager.Initialize();
 | 
| +
 | 
| +  // Create a texture.
 | 
| +  const GLuint kClientId = 1;
 | 
| +  const GLuint kServiceId = 11;
 | 
| +  manager.CreateTexture(kClientId, kServiceId);
 | 
| +  scoped_refptr<TextureRef> texture_ref(manager.GetTexture(kClientId));
 | 
| +  manager.SetTarget(texture_ref.get(), GL_TEXTURE_2D);
 | 
| +  GLint base_level = 2;
 | 
| +  GLint width = 4;
 | 
| +  GLint height = 4;
 | 
| +  manager.SetLevelInfo(texture_ref.get(), GL_TEXTURE_2D, base_level, GL_RGBA,
 | 
| +                       width, height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
 | 
| +                       gfx::Rect(4, 4));
 | 
| +
 | 
| +  SetParameter(texture_ref.get(), GL_TEXTURE_BASE_LEVEL, base_level,
 | 
| +               GL_NO_ERROR);
 | 
| +
 | 
| +  EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0))
 | 
| +      .Times(1)
 | 
| +      .RetiresOnSaturation();
 | 
| +  EXPECT_CALL(*gl_, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
 | 
| +                               GL_UNSIGNED_BYTE, nullptr))
 | 
| +      .Times(1)
 | 
| +      .RetiresOnSaturation();
 | 
| +  EXPECT_CALL(*gl_,
 | 
| +              TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, base_level))
 | 
| +      .Times(1)
 | 
| +      .RetiresOnSaturation();
 | 
| +
 | 
| +  TextureManager::DoTexImageArguments args = {
 | 
| +      GL_TEXTURE_2D,
 | 
| +      0,
 | 
| +      GL_RGBA,
 | 
| +      1,
 | 
| +      1,
 | 
| +      1,
 | 
| +      0,
 | 
| +      GL_RGBA,
 | 
| +      GL_UNSIGNED_BYTE,
 | 
| +      nullptr,
 | 
| +      0,
 | 
| +      0,
 | 
| +      TextureManager::DoTexImageArguments::kTexImage2D};
 | 
| +  EXPECT_CALL(*gl_, GetError())
 | 
| +      .WillOnce(Return(GL_NO_ERROR))
 | 
| +      .WillOnce(Return(GL_NO_ERROR))
 | 
| +      .RetiresOnSaturation();
 | 
| +  DecoderTextureState texture_state_(feature_info_->workarounds());
 | 
| +  texture_state_.tex_image_failed = true;
 | 
| +  DecoderFramebufferState framebuffer_state_;
 | 
| +  ContextState state_(feature_info_.get(), NULL, NULL);
 | 
| +  const char* func_name = "glTexImage2D";
 | 
| +  manager.DoTexImage(&texture_state_, &state_, &framebuffer_state_, func_name,
 | 
| +                     texture_ref.get(), args);
 | 
| +
 | 
| +  EXPECT_CALL(*gl_, DeleteTextures(1, ::testing::Pointee(kServiceId)))
 | 
| +      .Times(1)
 | 
| +      .RetiresOnSaturation();
 | 
| +  manager.RemoveTexture(kClientId);
 | 
| +}
 | 
| +
 | 
|  class TextureTestBase : public GpuServiceTest {
 | 
|   public:
 | 
|    static const GLint kMaxTextureSize = 32;
 | 
| 
 |